SendMessageTimeout function

Sends the specified message to one or more windows.

Syntax


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

Parameters

hWnd [in]

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.

Msg [in]

Type: UINT

The message to be sent.

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

wParam [in]

Type: WPARAM

Any additional message-specific information.

lParam [in]

Type: LPARAM

Any additional message-specific information.

fuFlags [in]

Type: UINT

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

ValueMeaning
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.

 

uTimeout [in]

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.

lpdwResult [out, optional]

Type: PDWORD_PTR

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

Return value

Type:

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.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

Unicode and ANSI names

SendMessageTimeoutW (Unicode) and SendMessageTimeoutA (ANSI)

See also

Reference
GetMessage
InSendMessage
PostMessage
SendDlgItemMessage
SendMessage
SendMessageCallback
SendNotifyMessage
Conceptual
Messages and Message Queues

 

 

Community Additions

ADD
Show:
© 2014 Microsoft