Reputation:
If a specified rectangle on my Window is invalid (i.e. it needs to be painted), a WM_PAINT
message is posted to the message queue, and if I did not validate the rectangle in the WM_PAINT
event handler, then a new WM_PAINT
message is posted to the message queue.
Is this correct?
If it is correct, then how does Windows knows not to keep sending WM_PAINT
messages, what I mean is how does Windows knows to wait until I finish handling the WM_PAINT
event and then send a new WM_PAINT
message if I did not validate the rectangle, and not to send a new WM_PAINT
message directly after I dequeue the WM_PAINT
message from the message queue?
Upvotes: 1
Views: 1418
Reputation: 612993
How does Windows know to wait until I finish handling the WM_PAINT event and then send a new WM_PAINT message if I did not validate the rectangle?
You handle WM_PAINT
by calling BeginPaint
, then painting, and then calling EndPaint
. The region that you paint is marked as valid when you call EndPaint
.
... and not to send a new WM_PAINT message directly after I dequeue the WM_PAINT message from the message queue?
Windows generates WM_PAINT
messages when you process the message queue. It will only generate WM_PAINT
messages when there are invalid regions. Once you have painted, there are no more invalid regions, and so no WM_PAINT
messages are generated.
Note that Windows, typically, does not send WM_PAINT
messages. These are asynchronous messages that are retrieved when your application's message loop pulls messages from the message queue. For instance, when you call GetMessage
, and the message queue is empty, and there are invalid regions, then WM_PAINT
messages are generated.
The exception to the statement above is when calls to UpdateWindow
and RedrawWindow
are made. In those scenarios, WM_PAINT
messages are sent synchronously. From the documentation:
The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function.
Upvotes: 3