win32gui获取当前所有窗口句柄
时间: 2024-03-11 12:15:43 浏览: 408
获取窗口句柄工具
4星 · 用户满意度95%
win32gui可以通过以下代码获取当前所有窗口的句柄:
```python
import win32gui
def winEnumHandler(hwnd, ctx):
print(hwnd)
win32gui.EnumWindows(winEnumHandler, None)
```
这段代码通过`EnumWindows`函数遍历系统中的所有窗口,并将每个窗口的句柄打印出来。使用`winEnumHandler`函数作为回调函数,在遍历时会对每个窗口调用该函数,并将窗口的句柄作为参数传入。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* [python win32gui 遍历所有窗口 根据标题获取句柄 关闭这个标题的窗口 遍历窗口 获取句柄](https://blog.csdn.net/nongcunqq/article/details/123358714)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item]
- *2* *3* [Python 使用 win32gui+win32api 通过鼠标获取句柄](https://blog.csdn.net/LelerTop/article/details/131327297)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文