Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
Windowing
Functions
 SendMessage Function
SendMessage Function

Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.

To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.

Syntax

LRESULT SendMessage(      
    HWND hWnd,     UINT Msg,     WPARAM wParam,     LPARAM lParam );

Parameters

hWnd
[in] 

Handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.

Microsoft Windows Vista and later. Message sending is subject to User Interface Privilege Isolation (UIPI). The thread of a process can send messages only to message queues of threads in processes of lesser or equal integrity level.

Msg
[in] Specifies the message to be sent.
wParam
[in] Specifies additional message-specific information.
lParam
[in] Specifies additional message-specific information.

Return Value

The return value specifies the result of the message processing; it depends on the message sent.

Remarks

Microsoft Windows Vista and later. When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).

Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication.

The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= WM_USER) to another process, you must do custom marshalling.

If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. For more information on nonqueued messages, see Nonqueued Messages.

Windows 95/98/Me: SendMessageW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Example

For an example, see Displaying Keyboard Input.

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 3.1
UnicodeImplemented as ANSI and Unicode versions.

See Also

Messages and Message Queues Overview, InSendMessage, PostMessage, PostThreadMessage, RegisterWindowMessage, SendDlgItemMessage, SendMessageCallback, SendMessageTimeout, SendNotifyMessage
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Svansa      Svansa ... Noelle Mallory - MSFT   |   Edit   |  
Keep up the good work and dont vanish

More easy ways to people contribute with your work.

World peace, thanks

Svansa
Tags What's this?: Add a tag
Flag as ContentBug
Kind of Messages      MrViSiOn2   |   Edit   |  
HI:
Where can I find all kind of messages that exists for this function?
Thanks
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker