企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## win32gui ### 获取所有系统中的窗口句柄 ``` def _MyCallback(hwnd, windows): temp = [] temp.append(hex(hwnd)) temp.append(win32gui.GetClassName(hwnd)) temp.append(win32gui.GetWindowText(hwnd)) windows[hwnd] = temp windows = {} win32gui.EnumWindows(_MyCallback, windows) ``` 比如,微信PC端会有2个窗口句柄: ``` ['0x10816', 'TrayNotifyWnd', '微信'] ['0x1b0734', 'WeChatMainWndForPC', '微信'] ``` ### 查找句柄 ``` win32gui.FindWindow("WeChatMainWndForPC", "微信") ``` ### 获取屏幕缩放比 ``` import win32gui, win32print, win32con hDC = win32gui.GetDC(0) dpi1 = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES) dpi2 = win32print.GetDeviceCaps(hDC, win32con.HORZRES) scale_factor = dpi1 / dpi2 ``` ## 推荐阅读 1. [python 使用win32api截图全解释](https://www.cnblogs.com/enumx/p/12336441.html)