LRESULT SendMessage(hwnd, uMsg, wParam, lParam) | |||||
HWND hwnd; | /* handle of destination window | */ | |||
UINT uMsg; | /* message to send, */ | ||||
WPARAM wParam; | /* first message parameter | */ | |||
LPARAM lParam; | /* second message parameter | */ |
The SendMessage function sends the specified message to the given window or windows. The function calls the window procedure for the window and does not return until that window procedure has processed the message. This is in contrast to the PostMessage function, which places (posts) the message in the window's message queue and returns immediately.
hwnd
Identifies the window to which the message will be sent. If this parameter is HWND_BROADCAST, the message will be sent to all top-level windows, including disabled or invisible unowned windows.
uMsg
Specifies the message to be sent.
wParam
Specifies 16 bits of additional message-dependent information.
lParam
Specifies 32 bits of additional message-dependent information.
The return value specifies the result of the message processing and depends on the message sent.
If the message is being sent to another application and the wParam or lParam parameter is used to pass a handle or pointer to global memory, the memory should be allocated by the GlobalAlloc function using the GMEM_SHARE flag.
The following example calls the SendMessage function to send an EM_SETSEL message to a multiline edit control, telling it to select all the text. It then calls SendMessage to send a WM_COPY message to copy the selected text to the clipboard.
SendMessage(hwndMle, EM_SETSEL, 0, MAKELONG(0, -1));
SendMessage(hwndMle, WM_COPY, 0, 0L);