MsgWaitForMultipleObjects

This function returns when one of the specified objects is in the signaled state, or when the time-out interval elapses. This function does not return if there is unread input of the specified type in the queue. It returns only when new input arrives.

At a Glance

Header file: Winuser.h
Windows CE versions: 2.0 and later

Syntax

DWORD MsgWaitForMultipleObjectsEx(DWORD nCount,
LPHANDLE pHandles, BOOL fWaitAll, DWORD dwMilliseconds,
DWORD dwWakeMasks);

Parameters

nCount

[in] Specifies the number of object handles in the array pointed to by pHandles. The maximum number of object handles is MAXIMUM_WAIT_OBJECTS minus one.

pHandles

[in] Pointer to an array of object handles. For a list of the object types whose handles can be specified, see the following Remarks section. The array can contain handles of objects of different types.

fWaitAll

[in] Unsupported; set to FALSE.

dwMilliseconds

[in] Specifies the time-out interval, in milliseconds. The function returns if the interval elapses, even if the criteria specified by the dwWakeMask parameter have not been met. If dwMilliseconds is zero, the function tests the states of the specified objects and returns immediately. If dwMilliseconds is INFINITE, the function’s time-out interval never elapses.

dwWakeMask

[in] Specifies input types for which an input event object handle will be added to the array of object handles. This parameter can be any combination of the following values:

Value Description
QS_ALLEVENTS An input, WM_TIMER, WM_PAINT, WM_HOTKEY, or posted message is in the queue.
QS_ALLINPUT Any message is in the queue.
QS_ALLPOSTMESSAGE A posted message (other than those listed here) is in the queue.
QS_HOTKEY A WM_HOTKEY message is in the queue.
QS_INPUT An input message is in the queue.
QS_KEY A WM_KEYUP, WM_KEYDOWN, WM_SYSKEYUP, or WM_SYSKEYDOWN message is in the queue.
QS_MOUSE A WM_MOUSEMOVE message or mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on).
QS_MOUSEBUTTON A mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on).
QS_MOUSEMOVE A WM_MOUSEMOVE message is in the queue.
QS_PAINT A WM_PAINT message is in the queue.
QS_POSTMESSAGE A posted message (other than those just listed) is in the queue.
QS_SENDMESSAGE A message sent by another thread or application is in the queue.
QS_TIMER A WM_TIMER message is in the queue.

Return Values

If the function succeeds, the return value indicates the event that caused the function to return. The successful return value is one of the following:

WAIT_OBJECT_0 to (WAIT_OBJECT_0 + nCount –1)

The return value minus WAIT_OBJECT_0 indicates the pHandles array index of the object that satisfied the wait.

WAIT_OBJECT_0 + nCount

New input of the type specified in the dwWakeMask parameter is available in the thread’s input queue. Functions such as PeekMessage and GetMessage mark messages in the queue as old messages. Therefore, after you call one of these functions, a subsequent call to MsgWaitForMultipleObjects will not return until new input of the specified type arrives.

This value is also returned upon the occurrence of a system event that requires the thread’s action, such as foreground activation. Therefore, MsgWaitForMultipleObjects can return even though no appropriate input is available and even if dwWaitMask is set to 0. If this occurs, call PeekMessage or GetMessage to process the system event before trying the call to MsgWaitForMultipleObjects again.

WAIT_ABANDONED_0 to (WAIT_ABANDONED_0 + nCount –1)

The return value minus WAIT_ABANDONED_0 indicates the pHandles array index of an abandoned mutex object that satisfied the wait.

WAIT_TIMEOUT

The time-out interval elapsed and the conditions specified by the  dwWakeMask parameter were not satisfied.

0xFFFFFFFF indicates failure. To get extended error information, call GetLastError.

Remarks

The MsgWaitForMultipleObjects function is implemented as a macro that calls MsgWaitForMultipleObjectsEx, passing 0 in the dwFlags parameter.

The MsgWaitForMultipleObjects function determines whether the wait criteria have been met. If the criteria have not been met, the calling thread enters an efficient wait state, using very little processor time while waiting for the conditions of the wait criteria to be met.

Before returning, a wait function modifies the state of some types of synchronization objects. Modification occurs only for the object or objects whose signaled state caused the function to return. For example, the count of a semaphore object is decreased by one. When fWaitAll is FALSE, and multiple objects are in the signaled state, the function chooses one of the objects to satisfy the wait; the states of the objects not selected are unaffected.

The MsgWaitForMultipleObjects function can specify handles of the following object types in the pHandles array:

The QS_ALLPOSTMESSAGE and QS_POSTMESSAGE flags differ in when they are cleared. QS_POSTMESSAGE is cleared when you call GetMessage or PeekMessage, whether or not you are filtering messages. QS_ALLPOSTMESSAGE is cleared when you call GetMessage or PeekMessage without filtering messages (wMsgFilterMin and wMsgFilterMax are 0). This can be useful when you call PeekMessage multiple times to get messages in different ranges.

See Also

MsgWaitForMultipleObjectsEx, WaitForMultipleObjects