{"id":7463,"date":"2012-06-04T07:00:00","date_gmt":"2012-06-04T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/06\/04\/why-does-printwindow-hate-cs_parentdc-because-everybody-hates-cs_parentdc\/"},"modified":"2012-06-04T07:00:00","modified_gmt":"2012-06-04T07:00:00","slug":"why-does-printwindow-hate-cs_parentdc-because-everybody-hates-cs_parentdc","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20120604-00\/?p=7463","title":{"rendered":"Why does PrintWindow hate CS_PARENTDC? Because EVERYBODY hates CS_PARENTDC!"},"content":{"rendered":"<p>Commenter kero wants to know <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/07\/20\/10040074.aspx#10040920\"> why the <code>Print&shy;Window<\/code> function hates <code>CS_PARENT&shy;DC<\/code><\/a>. (And <code>CS_CLASS&shy;DC<\/code>, and <code>CS_OWN&shy;DC<\/code>.)\n Because <i>everybody<\/i> hates <code>CS_PARENT&shy;DC<\/code>! (And <code>CS_CLASS&shy;DC<\/code>, and <code>CS_OWN&shy;DC<\/code>.)\n We saw earlier that these class styles <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2006\/06\/01\/612970.aspx\"> violate widely-held assumptions about how drawing works<\/a>. I mean, who would have thought that asking for two device contexts would give you the same one back twice? Or that changes to one device context would secretly modify another (because they&#8217;re really the same)? Or that a window procedure assumes that it will see only one device context <i>ever<\/i>?\n The <code>Print&shy;Window<\/code> function is really in a pickle when faced with a window with one of these class styles, because the whole point of <code>Print&shy;Window<\/code> is to render into some <i>other<\/i> device context. The <code>Print&shy;Window<\/code> function says &#8220;Render into this other device context, please,&#8221; and the window acts like a bratty two-year-old who refuses to eat food from anything other than his favorite <a href=\"http:\/\/www.bing.com\/shopping\/search?q=monkey+plate\"> monkey plate<\/a>. &#8220;This is not my monkey plate. I will now throw a tantrum.&#8221;\n The <code>Print&shy;Window<\/code> function passes a custom device context as a parameter to the <code>WM_PRINT<\/code> message, and the window says, &#8220;Hey, no fair! My class styles say that you aren&#8217;t allowed to pass any old device context; you have to pass <i>mine<\/i>. I will now take my broccoli and mash it all over the table.&#8221;\n Oh well. At least it tried.<\/p>\n<p> Yet another reason to avoid these weird class styles. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Commenter kero wants to know why the Print&shy;Window function hates CS_PARENT&shy;DC. (And CS_CLASS&shy;DC, and CS_OWN&shy;DC.) Because everybody hates CS_PARENT&shy;DC! (And CS_CLASS&shy;DC, and CS_OWN&shy;DC.) We saw earlier that these class styles violate widely-held assumptions about how drawing works. I mean, who would have thought that asking for two device contexts would give you the same one [&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-7463","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Commenter kero wants to know why the Print&shy;Window function hates CS_PARENT&shy;DC. (And CS_CLASS&shy;DC, and CS_OWN&shy;DC.) Because everybody hates CS_PARENT&shy;DC! (And CS_CLASS&shy;DC, and CS_OWN&shy;DC.) We saw earlier that these class styles violate widely-held assumptions about how drawing works. I mean, who would have thought that asking for two device contexts would give you the same one [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7463","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=7463"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7463\/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=7463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=7463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=7463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}