My goal is simple. If I create a window manually I activate persistent. If the user clicks close, I set persistent to 0, and the script should exit. It's not exiting!
Code: Select all
new_window()
new_window() {
WindowProc(hwnd, uMsg, wParam, lParam) {
; DOES NOT WORK
if (uMsg = 0x2) ; WM_DESTROY
return Persistent(false)
return DllCall("DefWindowProc", "ptr", hwnd, "uint", uMsg, "uptr", wParam, "ptr", lParam, "ptr")
}
; Make it permanent.
Persistent(true)
cls := "MyClass"
pWndProc := CallbackCreate(WindowProc, "Fast")
hCursor := DllCall("LoadCursor", "ptr", 0, "ptr", 32512, "ptr") ; IDC_ARROW
hBrush := DllCall("GetStockObject", "int", 5, "ptr") ; Hollow_brush
_ := (A_PtrSize = 4)
wc := Buffer(_ ? 48:80, 0) ; sizeof(WNDCLASSEX) = 48, 80
NumPut( "uint", wc.size, wc, 0) ; cbSize
NumPut( "uint", 0, wc, 4) ; style
NumPut( "ptr", pWndProc, wc, 8) ; lpfnWndProc
NumPut( "int", 0, wc, _ ? 12:16) ; cbClsExtra
NumPut( "int", 0, wc, _ ? 16:20) ; cbWndExtra
NumPut( "ptr", 0, wc, _ ? 20:24) ; hInstance
NumPut( "ptr", 0, wc, _ ? 24:32) ; hIcon
NumPut( "ptr", hCursor, wc, _ ? 28:40) ; hCursor
NumPut( "ptr", hBrush, wc, _ ? 32:48) ; hbrBackground
NumPut( "ptr", 0, wc, _ ? 36:56) ; lpszMenuName
NumPut( "ptr", StrPtr(cls), wc, _ ? 40:64) ; lpszClassName
NumPut( "ptr", 0, wc, _ ? 44:72) ; hIconSm
; Registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function.
DllCall("RegisterClassEx", "ptr", wc, "ushort")
WS_VISIBLE := 0x10000000
WS_SYSMENU := 0x80000
WS_CHILD := 0x40000000
WS_EX_TOPMOST := 0x8
WS_EX_LAYERED := 0x80000
WS_TILEDWINDOW := 0xCF0000
WS_CAPTION := 0xC00000
WS_EX_STATICEDGE := 0x20000
WS_EX_WINDOWEDGE := 0x100
WS_SIZEBOX := 0x40000
WS_CLIPCHILDREN := 0x2000000
WS_POPUP := 0x80000000
WS_BORDER := 0x800000
WS_EX_TOOLWINDOW := 0x80
WS_CLIPSIBLINGS := 0x4000000
WS_EX_TRANSPARENT := 0x20
WS_EX_DLGMODALFRAME := 0x1
style := WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_CLIPCHILDREN | WS_POPUP | WS_CLIPSIBLINGS
styleEx := WS_EX_TOPMOST | WS_EX_WINDOWEDGE | WS_EX_DLGMODALFRAME
hwnd := DllCall("CreateWindowEx"
, "uint", styleEx ; dwExStyle
, "str", cls ; lpClassName
, "str", "MyWindow" ; lpWindowName
, "uint", style ; dwStyle
, "int", 200 ; X
, "int", 200 ; Y
, "int", 500 ; nWidth
, "int", 500 ; nHeight
, "ptr", 0 ; hWndParent
, "ptr", 0 ; hMenu
, "ptr", 0 ; hInstance
, "ptr", 0 ; lpParam
, "ptr")
; This works.
; Persistent(false)
}