win32gui.EnumWindows
时间: 2023-12-01 11:02:53 浏览: 116
win32gui.EnumWindows is a function from the win32gui module in Python that is used to enumerate top-level windows owned by a specified process or all top-level windows on the desktop. It takes a callback function as a parameter, which is called for each window that is enumerated. The callback function should have the following signature:
```
def callback(hwnd, lparam):
# Do something with hwnd
return True
```
The hwnd parameter is the handle to the window that is being enumerated, and the lparam parameter is an optional parameter that can be used to pass additional data to the callback function.
The callback function should return True to continue the enumeration or False to stop it.
Here's an example of using EnumWindows to enumerate all top-level windows on the desktop:
```
import win32gui
def callback(hwnd, _):
print(win32gui.GetWindowText(hwnd))
win32gui.EnumWindows(callback, None)
```
This code will print the title of each top-level window on the desktop.
阅读全文
相关推荐















