There is a class of messages which are generated on demand
rather than explicitly posted into a message queue.
If you call GetÂMessage
or PeekÂMessage
and the queue is empty,
then the window manager will look to see if one of these
generated-on-demand messages is due,
messages like
WM_
,
WM_
,
and WM_
.
Neil wonders,
"In that program that called InvalidateÂRect
100,000 times,
how many paint messages were generated?"
The Zen answer to this question is "Yes."
A more practical answer is "As many as you can get."
When somebody calls InvalidateÂRect
,
the window manager adds the specified rectangle to the
window's invalid region (or invalidates the entire client
area if no rectangle is provided)
and sets a flag that says "Yo, there's painting to be done!"
(It's not actually a flag, but you can think of it that way.)
When a message retrieval function finds that there are no
incoming sent messages to be dispatched
nor any applicable messages in the queue to be retrieved,
it looks at these extra flags to see if it should generate
a message on the fly.
If the "Yo, there's painting to be done!" flag is set
on a window that the thread is responsible for,
a WM_
message is generated for that window.
(Similarly, a WM_
is generated if a timer
has elapsed, and a WM_
is generated
if the mouse has moved since the last time this thread
retrieved a mouse message.)
Therefore, the number of WM_
messages
by 100,000 invalidations is not deterministic,
but it'll be at least one and may be as high as 100,000.
It's basically just a race between the invalidation thread
and the paint thread.
InvalidateÂRect | |
InvalidateÂRect | |
GetÂMessage (retrieves WM_ ) | |
WM_ dispatched | |
GetÂMessage (waits for a message) | |
InvalidateÂRect | |
GetÂMessage (returns with WM_ ) | |
InvalidateÂRect | |
WM_ dispatched | |
InvalidateÂRect | |
GetÂMessage (retrieves WM_ ) | |
InvalidateÂRect | |
InvalidateÂRect | |
WM_ dispatched | |
GetÂMessage (retrieves WM_ ) | |
InvalidateÂRect | |
WM_ dispatched | |
GetÂMessage (retrieves WM_ ) | |
WM_ dispatched | |
GetÂMessage (waits for a message) |
If the thread doing the painting manages to call
GetÂMessage
between each call to
InvalidateÂRect
,
then it will see every invalidation.
On the other hand (which is more likely), it only manages to call
GetÂMessage
after a few invalidations have taken place,
it will see the accumulated invalidation
in a single WM_
message.
Now that you understand how generated messages work, you can answer this question which sometimes comes in:
If the user is continuously moving the mouse, how manySource : http://blogs.msdn.com/b/oldnewthing/archive/2011/12/19/10249000.aspxWM_
messages will I get?MOUSEÂMOVE