autoitfindwindowfindwindowex

FindWindowEx Windows API returns nothing in AutoIt


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.


Solution

  • 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:

    To test if a given window belongs to Notepad, you can:

    1. use GetWindowThreadProcessId() to get the window's owning process ID.
    2. then use OpenProcess() to open a handle to the process.
    3. then use GetModuleFileNameEx(), GetProcessImageFileName(), or QueryFullProcessImageName() to retrieve the path and filename of the EXE that created the process.
    4. check if the filename is notepad.exe and the path is the Windows system folder.