SendMessageTimeout Function

Sends the specified message to one of more windows.

Syntax

LRESULT SendMessageTimeout(      
    HWND hWnd,     UINT Msg,     WPARAM wParam,     LPARAM lParam,     UINT fuFlags,     UINT uTimeout,     PDWORD_PTR lpdwResult );

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. The function does not return until each window has timed out. Therefore, the total wait time can be up to the value of uTimeout multiplied by the number of top-level windows.

Msg
[in] Specifies the message to be sent.
wParam
[in] Specifies additional message-specific information.
lParam
[in] Specifies additional message-specific information.
fuFlags
[in] Specifies how to send the message. This parameter can be one or more of the following values.
SMTO_ABORTIFHUNG
Returns without waiting for the time-out period to elapse if the receiving thread appears to not respond or "hangs."
SMTO_BLOCK
Prevents the calling thread from processing any other requests until the function returns.
SMTO_NORMAL
The calling thread is not prevented from processing other requests while waiting for the function to return.
SMTO_NOTIMEOUTIFNOTHUNG
Microsoft Windows 2000/Windows XP: Do not enforce the time-out period as long as the receiving thread is processing messages.
SMTO_ERRORONEXIT
uTimeout
[in] Specifies the duration, in milliseconds, of the time-out period. If the message is a broadcast message, each window can use the full time-out period. For example, if you specify a five second time-out period and there are three top-level windows that fail to process the message, you could have up to a 15 second delay.
lpdwResult
[out] Receives the result of the message processing. This value depends on the message sent.

Return Value

If the function succeeds, the return value is nonzero. SendMessageTimeout does not provide information about individual windows timing out if HWND_BROADCAST is used.

If the function fails or times out, the return value is zero. To get extended error information, call GetLastError. If GetLastError returns ERROR_TIMEOUT, then the function timed out.

Microsoft Windows 2000: If GetLastError returns zero, then the function timed out.

Remarks

The function calls the window procedure for the specified window and, if the specified window belongs to a different thread, does not return until the window procedure has processed the message or the specified time-out period has elapsed. If the window receiving the message belongs to the same queue as the current thread, the window procedure is called directly—the time-out value is ignored.

This function considers a thread is not responding if it has not called GetMessage or a similar function within five seconds.

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.

Windows 95/98/Me: SendMessageTimeoutW 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.

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

Tags :


Community Content

Ciaran Gultnieks
Bad description & typo
On top of the fact that the main description is vague and doesn't describe the purpose of SendMessageTimeout at all, it says "Sends the specified message to one of more windows" when surely it means "Sends the specified message to one OR more windows"
Tags :

Simon Said
SMTO_ERRORONEXIT Flag - Description missing
No description has been provided for the SMTO_ERRORONEXIT flag.
Tags : contentbug

The MAZZTer
Purpose
Use SendMessageTimeout when sending messages to windows you do not control, when you need a response. If you use SendMessage, your program will hang if the window you sent to is hung.

Use PostMessage if you don't care about the return value.
Tags :

Page view tracker