一一列举Pywinauto 获取窗口句柄 的方法
- 使用pywinauto库中的Application类获取窗口句柄
from pywinauto import Application
app = Application().connect(title='Window Title')
handle = app.top_window().handle
- 使用pywinauto库中的findwindows.find_windows函数获取窗口句柄
from pywinauto import findwindows
handle = findwindows.find_windows(title='Window Title')[0]
- 使用Windows API函数FindWindow获取窗口句柄
import win32gui
handle = win32gui.FindWindow(None, 'Window Title')
- 使用Windows API函数EnumWindows遍历所有窗口,并使用GetWindowText和GetClassName函数获取窗口标题和类名,判断是否为目标窗口,获取窗口句柄
import win32gui
def get_handle(title):
def callback(handle, data):
if title in win32gui.GetWindowText(handle):
data.append(handle)
return True
handles = []
win32gui.EnumWindows(callback, handles)
return handles[0] if handles else None
handle = get_handle('Window Title')
原文地址: http://www.cveoy.top/t/topic/b7jr 著作权归作者所有。请勿转载和采集!