{"id":7073,"date":"2012-07-23T07:00:00","date_gmt":"2012-07-23T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/07\/23\/whats-the-story-behind-the-wm_syncpaint-message\/"},"modified":"2012-07-23T07:00:00","modified_gmt":"2012-07-23T07:00:00","slug":"whats-the-story-behind-the-wm_syncpaint-message","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20120723-00\/?p=7073","title":{"rendered":"What&#039;s the story behind the WM_SYNCPAINT message?"},"content":{"rendered":"<p>Danail wants to know <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/07\/20\/10040074.aspx#10040385\"> the story behind the <code>WM_SYNC&shy;PAINT<\/code> message<\/a>.\n <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd145221(VS.85).aspx\"> The documentation<\/a> pretty much tells the story. When a window has been hidden, shown, moved or sized, the system may determine that it needs to send a <code>WM_SYNC&shy;PAINT<\/code> message to the windows of other threads. This message must be passed to <code>Def&shy;Window&shy;Proc<\/code>, which will send the <code>WM_NCPAINT<\/code> and <code>WM_ERASE&shy;BKGND<\/code> messages to the window as necessary.\n When you call the <code>Set&shy;Window&shy;Pos<\/code> function, the window manager updates the window size, position, whatever, and then it goes around repainting the windows that were affected by the operation. By default, the <code>Set&shy;Window&shy;Pos<\/code> function does a quick-repaint of the windows before returning. After the function returns, the normal <code>WM_PAINT<\/code> message does the real work of painting the window. The quick-repaint is done so that there is immediate feedback that the window did change its size, position, whatever.\n This quick-repaint is done by sending a <code>WM_NCPAINT<\/code> and <code>WM_ERASE&shy;BKGND<\/code> message to the windows that were affected by the <code>Set&shy;Window&shy;Pos<\/code> operation. This normally happens without incident, but if one of the windows affected by the <code>Set&shy;Window&shy;Pos<\/code> operation belongs to another thread, the window manager needs to get into the context of that other thread to finish the job. That&#8217;s where <code>WM_SYNC&shy;PAINT<\/code> comes in. The <code>WM_SYNC&shy;PAINT<\/code> message means, &#8220;Hey, I was going around quick-painting a bunch of windows, but I couldn&#8217;t quick-paint you (or any other windows on your thread) because I was on the wrong thread. Could you finish quick-painting yourself (and all the other windows that need quick-painting)? Thanks.&#8221;\n Another way of looking at this is that it is a way for the window manager to teleport itself into another thread so it can finish its work. &#8220;Lah di dah, quick-painting all the windows, oh crap, I can&#8217;t quick-paint that window because it&#8217;s on the wrong thread. Let me inject myself into that other process [trivial, since <i>I&#8217;m the window manager<\/i>, <a href=\"http:\/\/dashes.com\/anil\/2007\/04\/cats-can-has-gr.html\"> I&#8217;M IN YR PROCESS REEDING YR MSGS<\/a>], and now I can send a message to myself [<code>WM_SYNCPAINT<\/code>], and when that other copy of me receives it, he&#8217;ll finish where I left off.&#8221;\n If you don&#8217;t like any of this teleportation or multiple-copies-of-yourself imagery, you can say that the <code>WM_SYNC&shy;PAINT<\/code> message means, &#8220;Quick-paint this window as part of a quick-paint operation begun on another thread.&#8221;<\/p>\n<p> If you don&#8217;t want this quick-paint to take place, you can follow the instructions in the documentation and <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms633545(VS.85).aspx\"> pass the <code>SWP_DEFER&shy;ERASE<\/code> flag to suppress the <code>WM_SYNC&shy;PAINT<\/code> message<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Danail wants to know the story behind the WM_SYNC&shy;PAINT message. The documentation pretty much tells the story. When a window has been hidden, shown, moved or sized, the system may determine that it needs to send a WM_SYNC&shy;PAINT message to the windows of other threads. This message must be passed to Def&shy;Window&shy;Proc, which will send [&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":[26],"class_list":["post-7073","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Danail wants to know the story behind the WM_SYNC&shy;PAINT message. The documentation pretty much tells the story. When a window has been hidden, shown, moved or sized, the system may determine that it needs to send a WM_SYNC&shy;PAINT message to the windows of other threads. This message must be passed to Def&shy;Window&shy;Proc, which will send [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7073","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=7073"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7073\/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=7073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=7073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=7073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}