DispatchMessage

2.x

  LONG DispatchMessage(lpmsg)    
  const MSG FAR* lpmsg; /* address of structure with message */

The DispatchMessage function dispatches a message to a window. It is typically used to dispatch a message retrieved by the GetMessage function.

Parameters

lpmsg

Points to an MSG structure that contains the message. The MSG structure has the following form:

typedef struct tagMSG {     /* msg */
    HWND   hwnd;
    UINT   message;
    WPARAM wParam;
    LPARAM lParam;
    DWORD  time;
    POINT  pt;
} MSG;

The MSG structure must contain valid message values. If the lpmsg parameter points to a WM_TIMER message and the lParam parameter of the WM_TIMER message is not NULL, then lParam points to a function that is called instead of the window procedure.

For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.

Return Value

The return value specifies the value returned by the window procedure. Although its meaning depends on the message being dispatched, generally the return value is ignored.

Example

The following example shows a typical use of the DispatchMessage function in an application's main message loop:

MSG msg;
HWND hwnd;
HWND hwndDlgModeless;
HANDLE haccl;

while (GetMessage(&msg, NULL, 0, 0)) {
    if ((hwndDlgModeless == NULL ||
            !IsDialogMessage(hwndDlgModeless, &msg)) &&
            !TranslateAccelerator(hwnd, haccl, &msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

See Also

GetMessage, PeekMessage, PostAppMessage, PostMessage, TranslateMessage