Python: cannot find the handle with win32gui.FindWindowEx()
Question: I'm trying to ge the handle for "Yes" button in a dialog, so I can send the
message to click it.

I get the dialog and then I try to find the button, but I always get 0 back.

    
    
    import win32gui
    
    hwnd = win32gui.FindWindow("#32770", "Programs and Features")
    # got back the correct handle to the dialog
    
    win32gui.SetForegroundWindow(hwnd)
    
    btnhdl = win32gui.FindWindowEx(hwnd, 0, "Button", "&Yes")
    # returns 0
    

The button is there and the class and title seem to be ok. I verified it by
this:

    
    
    def printClasses(childHwnd, lparam):
        if win32gui.GetWindowText(childHwnd) == "&Yes":
            print win32gui.GetClassName(childHwnd), win32gui.GetWindowText(childHwnd)
        return 1
    
    win32gui.EnumChildWindows(hwnd, printClasses, None)
    # output: Button &Yes
    

Looks like everything should be fine, but why it doesn't return the handle
with `FindWindowEx`?

Thanks


Answer: [From the comments in the OP] Maybe the button is a child of a child, ie a
grandchild? IIRC `EnumChildWindow` enumerates recursively while `FindWindowEx`
does not.

