{"id":4263,"date":"2013-05-24T07:00:00","date_gmt":"2013-05-24T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/05\/24\/what-happens-if-i-manually-post-an-auto-generated-message-into-my-message-queue\/"},"modified":"2013-05-24T07:00:00","modified_gmt":"2013-05-24T07:00:00","slug":"what-happens-if-i-manually-post-an-auto-generated-message-into-my-message-queue","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130524-00\/?p=4263","title":{"rendered":"What happens if I manually post an auto-generated message into my message queue?"},"content":{"rendered":"<p>As we well know, the window manager <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/05\/23\/10420741.aspx\"> generates various messages on-demand<\/a> 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 <code>Post&shy;Message(hwnd, WM_PAINT, 0, 0)<\/code>? Does that clear the internal flag that says &#8220;This window needs a paint message?&#8221;<\/p>\n<p> Nope. <\/p>\n<p> The window manager <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/09\/26\/10216420.aspx\"> does not have a prank call detector<\/a>. If you post a fake <code>WM_PAINT<\/code> message, then a fake <code>WM_PAINT<\/code> message shows up in the message queue. The part of the window manager which manages the &#8220;Does this window need to be repainted?&#8221; does not wiretap every telephone call to see if somebody is prank-calling a window with the <code>WM_PAINT<\/code> message, and then say, &#8220;You know what? I&#8217;m going to make that prank call a reality and make it act like a real <code>WM_PAINT<\/code> message.&#8221; <\/p>\n<p> Imagine if the act of prank-calling somebody <a href=\"http:\/\/answers.yahoo.com\/question\/index?qid=20070912174540AAHge9P\"> caused Prince Albert to stop by for a visit<\/a>! <\/p>\n<p> 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. <\/p>\n<p> It then follows as a consequence that if you post one of these auto-generated messages, <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/12\/19\/10249000.aspx#10250473\"> like <code>WM_TIMER<\/code> message<\/a>, you don&#8217;t get any magical coalescing behavior because the coalescing happens as part of the auto-generation, not as part of the <code>Post&shy;Message<\/code>. 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. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&shy;Message(hwnd, WM_PAINT, 0, 0)? Does that clear the internal flag that says &#8220;This window needs a paint message?&#8221; Nope. [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-4263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>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&shy;Message(hwnd, WM_PAINT, 0, 0)? Does that clear the internal flag that says &#8220;This window needs a paint message?&#8221; Nope. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/4263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=4263"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/4263\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=4263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=4263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=4263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}