Processing the Messages

Each message that a window procedure receives is identified by a number, which is the message parameter to the window procedure. The WINDOWS.H header file defines identifiers beginning with the prefix WM (”window message“) for each message parameter.

Generally, Windows programmers use a switch and case construction to determine what message the window procedure is receiving and how to process it accordingly. When a window procedure processes a message, it should return 0 from the window procedure. All messages that a window procedure chooses not to process must be passed to a Windows function named DefWindowProc. The value returned from DefWindowProc must be returned from the window procedure.

In HELLOWIN, WndProc chooses to process only two messages: WM_PAINT and WM_DESTROY. The window procedure is structured like this:

switch (message)

{

case WM_PAINT :

[ process WM_PAINT message ]

return 0 ;

case WM_DESTROY :

[ process WM_DESTROY message ]

return 0 ;

}

return DefWindowProc (hwnd, message, wParam, lParam) ;

It is essential to call DefWindowProc for all messages that your window procedure does not process.