Windows API Reference

Microsoft Developer Network

DispatchMessage Function

The DispatchMessage function passes scrolling information to the designated destination window procedure. There are no return values for this function. It returns control to the application when the message has been processed.

Parameters

Parameter Type and Description
lpMsg Pointer to a MSG structure that contains message information. This parameter can be NULL.

Return Value

This function does not return a value.

Remarks

The DispatchMessage function retrieves messages from the application queue and displays them in the appropriate window. If the thread that calls DispatchMessage has the highest-priority, the system sends the message directly to the destination window procedure. Otherwise, the message is placed in the thread's message queue and retrieved by the next call to GetMessage.

This function is typically called within a message loop, often in conjunction with the GetMessage function.

Example

Here's a simplified illustration of how DispatchMessage is used in a message loop:

BOOL GetMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax);
BOOL TranslateMessage(CONST MSG *lpMsg);
LRESULT DispatchMessage(CONST MSG *lpMsg);

// Message loop
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}