{"id":12543,"date":"2010-10-13T07:00:00","date_gmt":"2010-10-13T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/10\/13\/how-do-i-get-the-color-depth-of-the-screen\/"},"modified":"2010-10-13T07:00:00","modified_gmt":"2010-10-13T07:00:00","slug":"how-do-i-get-the-color-depth-of-the-screen","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20101013-00\/?p=12543","title":{"rendered":"How do I get the color depth of the screen?"},"content":{"rendered":"<p>\nHow do I get the color depth of the screen?\nThis question already makes an assumption that isn&#8217;t always true,\nbut we&#8217;ll answer the question first, then discuss why the answer is wrong.\n<\/p>\n<p>\nIf you have a device context for the screen, you can query\nthe color depth with a simple arithmetic calculation:\n<\/p>\n<pre>\ncolorDepth = GetDeviceCaps(hdc, BITSPIXEL) *\n             GetDeviceCaps(hdc, <a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2004\/12\/01\/273018.aspx\">PLANES<\/a>);\n<\/pre>\n<p>\nNow that you have the answer, I&#8217;ll explain why it&#8217;s wrong,\nbut you can probably guess the reason already.\n<\/p>\n<p>\nTwo words:\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2009\/12\/07\/9933241.aspx\">\nMultiple monitors<\/a>.\n<\/p>\n<p>\nIf you have multiple monitors connected to your system,\neach one can be running at a different color depth.\nFor example, your primary monitor might be running at 32 bits per pixel,\nwhile the secondary is stuck at 16 bits per pixel.\nWhen there was only one monitor, there was such a thing as <i>the<\/i>\ncolor depth of the screen,\nbut when there&#8217;s more than one,\nyou first have to answer the question,\n&#8220;Which screen?&#8221;\n<\/p>\n<p>\nTo get the color depth of each monitor, you can take your device\ncontext and ask the window manager to chop the device context\ninto pieces, each corresponding to a different monitor.\n<\/p>\n<pre>\nEnumDisplayMonitors(hdc, NULL, MonitorEnumProc, 0);\n\/\/ this function is called once for each \"piece\"\nBOOL CALLBACK MonitorEnumProc(HMONITOR hmon, HDC hdc,\n                              LPRECT prc, LPARAM lParam)\n{\n   \/\/ compute the color depth of monitor \"hmon\"\n   int colorDepth = GetDeviceCaps(hdc, BITSPIXEL) *\n                    GetDeviceCaps(hdc, PLANES);\n   return TRUE;\n}\n<\/pre>\n<p>\nIf you decide to forego splitting the DC into pieces\nand just ask for &#8220;the&#8221; color depth,\nyou&#8217;ll get the color depth information for the primary\nmonitor.\n<\/p>\n<p>\nAs a bonus\n(<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2010\/02\/08\/9959494.aspx\">and possible optimization<\/a>),\nthere is a system metric\n<code>GetSystemMetrics(SM_SAMEDISPLAYFORMAT)<\/code>\nwhich has a nonzero value if all the monitors in the system\nhave the same color format.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How do I get the color depth of the screen? This question already makes an assumption that isn&#8217;t always true, but we&#8217;ll answer the question first, then discuss why the answer is wrong. If you have a device context for the screen, you can query the color depth with a simple arithmetic calculation: colorDepth = [&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-12543","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>How do I get the color depth of the screen? This question already makes an assumption that isn&#8217;t always true, but we&#8217;ll answer the question first, then discuss why the answer is wrong. If you have a device context for the screen, you can query the color depth with a simple arithmetic calculation: colorDepth = [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/12543","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=12543"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/12543\/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=12543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=12543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=12543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}