0

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

Alex Okrushko
  • 7,212
  • 6
  • 44
  • 63
  • 1
    Maybe the button is a child of a child, ie a grandchild? IIRC `EnumChildWindow` enumerates recursively while `FindWindowEx` does not. – rodrigo May 10 '12 at 19:19
  • @rodrigo Yes, that is correct. It is actually two levels down. From the question [EnumChildWindows or FindWindowEx](http://stackoverflow.com/questions/1823628/enumchildwindows-or-findwindowex) I got an impression that they work similar way. You should probably post it as an answer, so I can accept it. Thanks – Alex Okrushko May 10 '12 at 20:03

1 Answers1

2

[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.

rodrigo
  • 94,151
  • 12
  • 143
  • 190