Windows sends a message to the window, which means the Windows calls window message handler. However, the Windows program also has a message loop, which calls getMessage to remove the message from the message queue, and call DispatchMessage to send the message to the window message handler.
Then, the Windows program is waiting for the message (similar to the same keyboard input in a normal program), then send the message to a certain place? Or, do it receive messages directly from the program? In fact, both situations exist.
The message can be divided into "queue" and "non-queue". Queue messages are in the Windows in the program message queue. In the message loop of the program, it is retransmond and assigned to the window message handler. Non-queued messages directly to the window message handler when the Windows call window. That is, the queue's message is "Send" to the message queue, not the queue, "Send" to the window message handler. In any case, the window message handler will get all the messages of the window - including queue and non-queue. The window message handler is the "Message Center" of the window.
Queue messages are basically the result of the user input to hit the key (such as a WM_KEYDOWN and WM_KEYUP message), the word generated by the keys (WM_CHAR), the mouse movement (WM_MOUSEMOVE) and the mouse button (WM_LButtondown) are given. Queue messages also include clock messages (WM_TIMER), update messages (WM_PAINT), and exit messages (WM_QUIT).
Non-queen messages are other messages. In many cases, non-queen messages come from calling a specific Windows function. For example, when WinMain calls CREATEWINDOW, Windows will create a window and send a WM_CREATE message to the window message handler in the process. When WinMain calls ShowWindow, Windows will send WM_SIZE and WM_SHOWWINDOW messages to the window message handler. When WinMain calls UpdateWindow, Windows will send a WM_PAINT message to the window message handler. The queue message signal issued when the keyboard or mouse input can also appear in the non-queue message. For example, when selecting a menu item with a keyboard or mouse, the keyboard or mouse message is queue, and the WM_COMMAND message selected by the menu item may be non-queue.
Several methods for sending WM_Paint messages to Windows
1 Use postmessage (), sendM_Paint message ()
Use the above two functions to send a WM_PAINT message, you can send the WM_PAINT message to the Windows program message queue, when Windows sends the WM_PAINT message to the specific message processing function, if the invalid area of the window is empty, Windows will ignore the message. If there is an invalid area, the window processing function processing is called.
2 invalidate (), invalidateect (), invalidatergn ();
The above functions are calibrated to invalidate the specific area of the window, send WM_PAINT messages to the message queue when Windows detects an invalid area in the window.
3 UpdateWindow ()
After this function calls, Windows sends a non-queued WM_PAINT message to the window, which does not send the message loop to the window message processing function directly. If the window invalid area does not exist, Windows will ignore this message.