A message loop that receives and dispatches messages is the heart of every Windows CE-based application. Every thread that creates a window is continuously receiving messages and dispatching messages to window procedures.
You can use the GetMessage function to receive messages. When a thread calls GetMessage, Windows CE examines the thread's message queue for incoming messages. Windows CE processes messages in the following order:
By processing user input messages at a lower priority, the system guarantees that each input message and any posted messages that result from it are processed completely before moving on to the next input message.
When GetMessage receives any of the previous messages, it returns the message content. It is then the responsibility of the thread to call DispatchMessage to dispatch the message to the correct window procedure. If the message is a WM_QUIT message, the return value of GetMessage is zero, which causes the thread to end its message loop.
The system dispatches messages in the GetMessage call of the message loop, and the application dispatches messages by using the DispatchMessage function in the message loop. Windows CE handles the details of finding the window procedure of the receiver window.