May 24th, 2013

What happens if I manually post an auto-generated message into my message queue?

As we well know, the window manager generates various messages on-demand rather than posting them into the queue at the time the event occurs. But what happens if you manually post one of these messages, like Post­Message(hwnd, WM_PAINT, 0, 0)? Does that clear the internal flag that says “This window needs a paint message?”

Nope.

The window manager does not have a prank call detector. If you post a fake WM_PAINT message, then a fake WM_PAINT message shows up in the message queue. The part of the window manager which manages the “Does this window need to be repainted?” does not wiretap every telephone call to see if somebody is prank-calling a window with the WM_PAINT message, and then say, “You know what? I’m going to make that prank call a reality and make it act like a real WM_PAINT message.”

Imagine if the act of prank-calling somebody caused Prince Albert to stop by for a visit!

In particular, the posted message goes into the posted message queue and will rise to the front of the queue as messages are retrieved. On the other hand, the auto-generated message will remain in its proto-message state until the queue is finally empty.

It then follows as a consequence that if you post one of these auto-generated messages, like WM_TIMER message, you don’t get any magical coalescing behavior because the coalescing happens as part of the auto-generation, not as part of the Post­Message. These prank-call messages also appear in the message queue in posted order rather than being generated at low priority like normal auto-generated messages.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.