I'm using the following code to return handle for a open file dialog box shown from Notepad.
Global $Result = DllCall("User32.dll", "HWND", "FindWindowExA", "HWND", WinGetHandle("[CLASS:Notepad]"), "HWND", Null, "STR", "#32770", "STR", "Open")
ConsoleWrite("FindWindowEx Return Value: " & String($Result[0]) & @CRLF)
This always returns 0x00000000
, but given parameters seems correct.
Why does this function return nothing here?
UPDATE
The following syntax worked, but I still can't specify the parent window:
Global $Result = DllCall('User32.dll', 'HWND', 'FindWindowExW', 'HWND', Null, 'HWND', Null, 'WSTR', '#32770', 'WSTR', 'Open')
This finds every dialog box (Paint, WordPad etc.) , but I only want to get the handle to dialog box with parent as Notepad.
There is no single API to restrict the search to just Notepad. You will have to enumerate all available #32770
windows, looking for ones that belong to a Notepad process, until you find the one you are looking for.
To enumerate the windows, you can use either:
EnumWindows()
, filtering in the callback function using GetClassName()
and GetWindowText()
.
FindWindowEx()
in a loop, initially setting hwndParent=0
and hwndChildAfter=0
, and then setting hwndChildAfter
to the last found window on each subsequent call.
To test if a given window belongs to Notepad, you can:
GetWindowThreadProcessId()
to get the window's owning process ID.OpenProcess()
to open a handle to the process.GetModuleFileNameEx()
, GetProcessImageFileName()
, or QueryFullProcessImageName()
to retrieve the path and filename of the EXE that created the process.notepad.exe
and the path is the Windows system folder.