{"id":25643,"date":"2007-08-09T10:00:00","date_gmt":"2007-08-09T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2007\/08\/09\/how-do-i-get-the-handle-of-the-primary-monitor\/"},"modified":"2007-08-09T10:00:00","modified_gmt":"2007-08-09T10:00:00","slug":"how-do-i-get-the-handle-of-the-primary-monitor","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20070809-00\/?p=25643","title":{"rendered":"How do I get the handle of the primary monitor?"},"content":{"rendered":"<p>\nThe primary monitor by definition has its upper left corner at\n(0, 0).\nTherefore, you can use this function:\n<\/p>\n<pre>\nHMONITOR GetPrimaryMonitorHandle()\n{\n const POINT ptZero = { 0, 0 };\n return MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);\n}\n<\/pre>\n<p>\nTo make double extra sure (belt and suspenders),\nwe also tell it, &#8220;If you&#8217;re not sure\nwhat monitor to return, give us the primary.&#8221;\n<\/p>\n<p>\nSure, this sounds obviously simple, but I actually found somebody\nwho\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/06\/13\/629451.aspx\">\nfumbled around in the dark passing intentionally invalid\nparameters<\/a>\nto <code>MonitorFromWindow<\/code> trying to find one\nthat would return the primary monitor handle.\n(I&#8217;ve heard this called <i>Programming By Accident<\/i>.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The primary monitor by definition has its upper left corner at (0, 0). Therefore, you can use this function: HMONITOR GetPrimaryMonitorHandle() { const POINT ptZero = { 0, 0 }; return MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY); } To make double extra sure (belt and suspenders), we also tell it, &#8220;If you&#8217;re not sure what monitor to return, give [&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-25643","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The primary monitor by definition has its upper left corner at (0, 0). Therefore, you can use this function: HMONITOR GetPrimaryMonitorHandle() { const POINT ptZero = { 0, 0 }; return MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY); } To make double extra sure (belt and suspenders), we also tell it, &#8220;If you&#8217;re not sure what monitor to return, give [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/25643","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=25643"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/25643\/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=25643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=25643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=25643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}