SendMessageTimeoutA function (winuser.h)

Sends the specified message to one or more windows.

Syntax

LRESULT SendMessageTimeoutA(
  [in]            HWND       hWnd,
  [in]            UINT       Msg,
  [in]            WPARAM     wParam,
  [in]            LPARAM     lParam,
  [in]            UINT       fuFlags,
  [in]            UINT       uTimeout,
  [out, optional] PDWORD_PTR lpdwResult
);

Parameters

[in] hWnd

Type: HWND

A handle to the window whose window procedure will receive the message.

If this parameter is HWND_BROADCAST ((HWND)0xffff), 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.

[in] Msg

Type: UINT

The message to be sent.

For lists of the system-provided messages, see System-Defined Messages.

[in] wParam

Type: WPARAM

Any additional message-specific information.

[in] lParam

Type: LPARAM

Any additional message-specific information.

[in] fuFlags

Type: UINT

The behavior of this function. This parameter can be one or more of the following values.

Value Meaning
SMTO_ABORTIFHUNG
0x0002
The function returns without waiting for the time-out period to elapse if the receiving thread appears to not respond or "hangs."
SMTO_BLOCK
0x0001
Prevents the calling thread from processing any other requests until the function returns.
SMTO_NORMAL
0x0000
The calling thread is not prevented from processing other requests while waiting for the function to return.
SMTO_NOTIMEOUTIFNOTHUNG
0x0008
The function does not enforce the time-out period as long as the receiving thread is processing messages.
SMTO_ERRORONEXIT
0x0020
The function should return 0 if the receiving window is destroyed or its owning thread dies while the message is being processed.

[in] uTimeout

Type: UINT

The duration of the time-out period, in milliseconds. 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.

[out, optional] lpdwResult

Type: PDWORD_PTR

The result of the message processing. The value of this parameter depends on the message that is specified.

Return value

Type: LRESULT

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 0. To get extended error information, call GetLastError. If GetLastError returns ERROR_TIMEOUT, then the function timed out.

Windows 2000:  If GetLastError returns 0, 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 that 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.

Note

The winuser.h header defines SendMessageTimeout as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll
API set ext-ms-win-ntuser-message-l1-1-0 (introduced in Windows 8)

See also

Conceptual

GetMessage

InSendMessage

Messages and Message Queues

PostMessage

Reference

SendDlgItemMessage

SendMessage

SendMessageCallback

SendNotifyMessage