例如,首先,您必须找到Skype的hwnd
hwnd = win32gui.FindWindow(None, 'skype')
Run Code Online (Sandbox Code Playgroud)
比他所有的孩子窗户和标题
child = ???
Run Code Online (Sandbox Code Playgroud)
任何的想法?
此代码显示hwnd了具有WindowsText一定长度的EditPlus子窗口:
编辑
您将必须找到hwnd您的应用程序,然后将该句柄与配合使用EnumChildWindows。我用它扩展了示例代码。一旦获得应用程序,hwnd您就只能枚举其窗口。当您给0时hwnd,EnumChildWindows您将获得所有正在运行的窗口的句柄。将一些打印品添加到我的代码中并检查!
扩展代码:
import win32gui
MAIN_HWND = 0
def is_win_ok(hwnd, starttext):
s = win32gui.GetWindowText(hwnd)
if s.startswith(starttext):
print s
global MAIN_HWND
MAIN_HWND = hwnd
return None
return 1
def find_main_window(starttxt):
global MAIN_HWND
win32gui.EnumChildWindows(0, is_win_ok, starttxt)
return MAIN_HWND
def winfun(hwnd, lparam):
s = win32gui.GetWindowText(hwnd)
if len(s) > 3:
print("winfun, child_hwnd: %d txt: %s" % (hwnd, s))
return 1
def main():
main_app = 'EditPlus'
hwnd = win32gui.FindWindow(None, main_app)
print hwnd
if hwnd < 1:
hwnd = find_main_window(main_app)
print hwnd
if hwnd:
win32gui.EnumChildWindows(hwnd, winfun, None)
main()
Run Code Online (Sandbox Code Playgroud)