{"id":16733,"date":"2009-09-14T10:00:00","date_gmt":"2009-09-14T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/09\/14\/can-you-create-an-information-context-for-the-display\/"},"modified":"2009-09-14T10:00:00","modified_gmt":"2009-09-14T10:00:00","slug":"can-you-create-an-information-context-for-the-display","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090914-00\/?p=16733","title":{"rendered":"Can you create an information context for the display?"},"content":{"rendered":"<p>Adrian McCarthy asks, &#8220;<a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#654530\">Can you create an information context for the display?<\/a> &#8230; I can call CreateDC(&#8220;DISPLAY&#8221;), but perhaps that wouldn&#8217;t generalize for a multiple-monitor display with different settings on each screen. I&#8217;m trying to avoid constantly creating and destroying DCs when all I need to do is measure strings, check color depth, dpi, etc.&#8221;\n I admire the effort of trying to avoid creating a whole DC when all you want is to perform some inquiries. Some inquiries are monitor-independent, like getting the DPI or measuring strings, so you can just use <code>GetDC(NULL)<\/code> to get a temporary DC. This is cheaper than a full-on <code>CreateDC<\/code> since <code>GetDC<\/code> goes through <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/06\/01\/612970.aspx\"> the DC cache<\/a>, so you&#8217;re just grabbing a DC out of the cache temporarily, doing a little computation, and then returning it to the cache (with <code>ReleaseDC<\/code>).\n If you are doing something that is monitor-specific, like getting its color depth, you can <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms534598.aspx\"> call <code>EnumDisplayMonitors<\/code> on the desktop DC<\/a> to look at each monitor.\n (And just for completeness, to get the name for a specific monitor if you really do want to create an IC for it, call <code>GetMonitorInfo<\/code> with a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms534807.aspx\"> MONITORINFOEX<\/a> and look at the <code>szDevice<\/code> member.)<\/p>\n<p> <b>Update<\/b>: Original text said &#8220;DC&#8221; in the last sentence by mistake. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adrian McCarthy asks, &#8220;Can you create an information context for the display? &#8230; I can call CreateDC(&#8220;DISPLAY&#8221;), but perhaps that wouldn&#8217;t generalize for a multiple-monitor display with different settings on each screen. I&#8217;m trying to avoid constantly creating and destroying DCs when all I need to do is measure strings, check color depth, dpi, etc.&#8221; [&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-16733","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Adrian McCarthy asks, &#8220;Can you create an information context for the display? &#8230; I can call CreateDC(&#8220;DISPLAY&#8221;), but perhaps that wouldn&#8217;t generalize for a multiple-monitor display with different settings on each screen. I&#8217;m trying to avoid constantly creating and destroying DCs when all I need to do is measure strings, check color depth, dpi, etc.&#8221; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/16733","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=16733"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/16733\/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=16733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=16733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=16733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}