ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的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)