{"id":5823,"date":"2012-12-17T07:00:00","date_gmt":"2012-12-17T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/12\/17\/like-the-cake-ws_ex_transparent-is-a-lie-or-at-least-not-the-entire-truth\/"},"modified":"2012-12-17T07:00:00","modified_gmt":"2012-12-17T07:00:00","slug":"like-the-cake-ws_ex_transparent-is-a-lie-or-at-least-not-the-entire-truth","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20121217-00\/?p=5823","title":{"rendered":"Like the cake, WS_EX_TRANSPARENT is a lie, or at least not the entire truth"},"content":{"rendered":"<p>There is an extended window style known as <code>WS_EX_TRANSPARENT<\/code>. <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/07\/20\/10040074.aspx#10040814\"> Explaining what this style does<\/a> is kind of difficult, but it&#8217;s been on the list of future topics <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/09\/15\/54925.aspx#78373\"> since 2003<\/a>. Better late than never, I guess.\n First of all, there are two unrelated senses of <i>transparent<\/i> in play. One is visual transparency: Pixels beneath the window can show through. The other is hit-test transparency: Do clicks on this window go to the window, or do they pass through to the window beneath?\n And each of those senses of <i>transparent<\/i> is itself complicated.\n Let&#8217;s look a hit-test transparency first. We saw some time ago that <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/12\/30\/10110077.aspx\"> It&#8217;s Complicated<\/a>. Different hit-testing functions use different methods of determining whether a click should be given to a window or pass through it. And the <code>WS_EX_TRANSPARENT<\/code> extended window style plays into some of those rules. I&#8217;ll let you read the linked article to learn the details.\n Okay, now to visual transparency. The <code>WS_EX_TRANSPARENT<\/code> extended window style alters the painting algorithm as follows: If a <code>WS_EX_TRANSPARENT<\/code> window needs to be painted, and it has any non-<code>WS_EX_TRANSPARENT<\/code> windows siblings (which belong to the same process) which also need to be painted, then the window manager will paint the non-<code>WS_EX_TRANSPARENT<\/code> windows first.\n That &#8220;lets the other windows paint first&#8221; behavior is what gave the style its name, because if you let the other windows paint first, and then you paint on top of it, then the parts you don&#8217;t actually paint will appear to be transparent because the other windows&#8217; pixels will show through.\n Calling this painting style <i>transparent<\/i> is kind of overselling the feature. It&#8217;s really a very specific behavior which makes transparent rendering <i>sort of possible<\/i>; it&#8217;s not a <i>just turn this on and you get transparent rendering<\/i> feature.\n It&#8217;s like taking a lump of coal and labeling it <i>diamond<\/i>. Or like those advertisements which say things like &#8220;Can create <i>up to<\/i> five million cups of coffee per day!&#8221;\n In order to turn the flour into a cake, the window with the <code>WS_EX_TRANSPARENT<\/code> window style needs to know not to draw opaquely. Because if it draws opaquely, then all the work the window manager did to get the other window to draw first (so you can draw on top of it) is for naught.\n And sometimes the <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/10\/28\/10230811.aspx\"> <code>WS_EX_TRANSPARENT<\/code> window style doesn&#8217;t even work<\/a>. For example, observe that if the windows are not siblings of each other, then the style has no effect. If the windows belong to different processes, then the style has no effect. If both windows are not invalid simultaneously, then the style has no effect. (I don&#8217;t know how you could get into that last state, but maybe you&#8217;re more creative than I am.)<\/p>\n<p> Go ahead and use the <code>WS_EX_TRANSPARENT<\/code> window style if that&#8217;s what you want. Just understand that it doesn&#8217;t get you what the name might promise. (Depending on your situation, a layered window may work better.) <\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is an extended window style known as WS_EX_TRANSPARENT. Explaining what this style does is kind of difficult, but it&#8217;s been on the list of future topics since 2003. Better late than never, I guess. First of all, there are two unrelated senses of transparent in play. One is visual transparency: Pixels beneath the window [&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-5823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>There is an extended window style known as WS_EX_TRANSPARENT. Explaining what this style does is kind of difficult, but it&#8217;s been on the list of future topics since 2003. Better late than never, I guess. First of all, there are two unrelated senses of transparent in play. One is visual transparency: Pixels beneath the window [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5823","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=5823"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5823\/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=5823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=5823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=5823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}