{"id":43683,"date":"2014-11-06T07:00:00","date_gmt":"2014-11-06T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/11\/06\/how-do-i-get-a-handle-to-the-primary-monitor\/"},"modified":"2014-11-06T07:00:00","modified_gmt":"2014-11-06T07:00:00","slug":"how-do-i-get-a-handle-to-the-primary-monitor","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20141106-00\/?p=43683","title":{"rendered":"How do I get a handle to the primary monitor?"},"content":{"rendered":"<p>\nThere are various ways of getting a monitor.\nYou can get the monitor from a point,\nfrom a rectangle,\nor from a window.\nBut how do you get the primary monitor?\n<\/p>\n<p>\nThe primary monitor is defined to be the one\nwhich has (0, 0) as its origin.\nTherefore,\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2007\/08\/09\/4300545.aspx\">\none solution<\/a>\nis\n<\/p>\n<pre>\nHMONITOR GetPrimaryMonitor()\n{\n POINT ptZero = { 0, 0 };\n return MonitorFromPoint(ptZero,\n                         MONITOR_DEFAULTTOPRIMARY);\n}\n<\/pre>\n<p>\nThe desktop window by convention is deemed to reside\nprimarily on the primary monitor,\nso you could also use this:\n<\/p>\n<pre>\nHMONITOR GetPrimaryMonitor()\n{\n return MonitorFromWindow(GetDesktopWindow(),\n                          MONITOR_DEFAULTTOPRIMARY);\n}\n<\/pre>\n<p>\nOr you could just pass the null window handle.\nThis is technically an illegal parameter,\nbut by specifying\n<code>MONITOR_DEFAULT&shy;TO&shy;PRIMARY<\/code>,\nyou are saying,\n&#8220;If anything goes wrong,\ngive me the primary monitor.&#8221;\n<\/p>\n<pre>\nHMONITOR GetPrimaryMonitor()\n{\n return MonitorFromWindow(nullptr,\n                          MONITOR_DEFAULTTOPRIMARY);\n}\n<\/pre>\n<p>\nIn this case, we are intentionally going astray\nbecause we want to kick in the\n<code>MONITOR_DEFAULT&shy;TO&shy;PRIMARY<\/code>\nbehavior.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are various ways of getting a monitor. You can get the monitor from a point, from a rectangle, or from a window. But how do you get the primary monitor? The primary monitor is defined to be the one which has (0, 0) as its origin. Therefore, one solution is HMONITOR GetPrimaryMonitor() { POINT [&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-43683","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>There are various ways of getting a monitor. You can get the monitor from a point, from a rectangle, or from a window. But how do you get the primary monitor? The primary monitor is defined to be the one which has (0, 0) as its origin. Therefore, one solution is HMONITOR GetPrimaryMonitor() { POINT [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43683","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=43683"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43683\/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=43683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=43683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=43683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}