Message Routing:
The system posts the messages to a first-in, first-out queue known as the message queue or it sends the messages directly to a window procedure. The Messages posted to a message queue are known as the queued messages. These are the result of the user input entered through the mouse or the keyboard, like WM_KEYUP, WM_RBUTTONDOWN. The messages, sent directly to the window procedure are the non queued messages.
The Non queued messages are sent instantly to the destination window procedure, bypassing the system message queue and the thread message queue. The system sends the non queued messages to notify a window of events that influence it. For illustration, whenever the user activates a new application window, the system sends the window WM_SETFOCUS, WM_ACTIVATE, and WM_SETCURSOR messages. These messages notify the window which it has been activated, that the keyboard input is being directed to the window, and which the mouse cursor has been moved within the borders of the window. The Non-queued messages happen when an application calls certain system functions. For illustration, the system sends the WM_WINDOWPOSCHANGED message after an application uses the SetWindowPos function to move a window.