win32gui.SendMessage
时间: 2024-05-02 09:18:26 浏览: 17
win32gui.SendMessage is a function in the Python module win32gui that sends a message to a window or control in a Windows application. The function takes three arguments: hwnd, msg, and wparam.
hwnd is the handle to the window or control that will receive the message. This can be obtained using the win32gui.FindWindow or win32gui.FindWindowEx functions.
msg is the message to send. This parameter should be a Windows message constant, such as WM_CLOSE to close a window or WM_SETTEXT to set the text of a control.
wparam is an optional parameter that can be used to pass additional information to the message. The meaning of this parameter depends on the message being sent.
The function returns the result of the message, which can vary depending on the message being sent. For example, if the message is WM_GETTEXT, the result will be the text of the control.
Example usage:
```
import win32gui
# Find the window with the title "Untitled - Notepad"
hwnd = win32gui.FindWindow(None, "Untitled - Notepad")
# Send the WM_CLOSE message to the window to close it
win32gui.SendMessage(hwnd, win32con.WM_CLOSE, 0, 0)
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-dosexec](https://img-home.csdnimg.cn/images/20210720083343.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)