{"id":397,"date":"2008-06-19T20:25:08","date_gmt":"2008-06-19T18:25:08","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=397"},"modified":"2008-06-27T06:03:09","modified_gmt":"2008-06-27T04:03:09","slug":"atls-centerwindow","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/397","title":{"rendered":"ATL&#8217;s CenterWindow"},"content":{"rendered":"<p>It appears that ATL does not center window correctly on multi-monitor systems. ATL code checks screen work area coordinates in CWindow::CenterWindow to ensure new position is within visible area, however since <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms724947(VS.85).aspx\">SystemParametersInfo<\/a>\/SPI_GETWORKAREA is used target rectangle is always on a primary monitor.<\/p>\n<p>This hotfix works the problem around:<\/p>\n<p><!--more--><\/p>\n<p>atlwin.h, CWindow::CenterWindow:<\/p>\n<p><code><\/p>\n<pre>#if TRUE\r\n\tif(hWndCenter)\r\n\t{\r\n\t\tATLVERIFY(::GetWindowRect(hWndCenter, &rcCenter));\r\n\t\tHMONITOR hMonitor = MonitorFromRect(&rcCenter, MONITOR_DEFAULTTONEAREST);\r\n\t\tATLASSERT(hMonitor);\r\n\t\tif(hMonitor)\r\n\t\t{\r\n\t\t\tMONITORINFO MonitorInfo = { sizeof MonitorInfo };\r\n\t\t\tATLVERIFY(GetMonitorInfo(hMonitor, &MonitorInfo));\r\n\t\t\trcArea = MonitorInfo.rcWork;\r\n\t\t} else\r\n\t\t\tATLVERIFY(::SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcArea, NULL));\r\n\t} else\r\n\t{\r\n\t\tATLVERIFY(::SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcArea, NULL));\r\n\t\trcCenter = rcArea;\r\n\t}\r\n#else\r\n\t::SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcArea, NULL);\r\n\tif(hWndCenter == NULL)\r\n\t\trcCenter = rcArea;\r\n\telse\r\n\t\t::GetWindowRect(hWndCenter, &rcCenter);\r\n#endif\r\n<\/pre>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It appears that ATL does not center window correctly on multi-monitor systems. ATL code checks screen work area coordinates in CWindow::CenterWindow to ensure new position is within visible area, however since SystemParametersInfo\/SPI_GETWORKAREA is used target rectangle is always on a primary monitor. This hotfix works the problem around:<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,21,13],"tags":[487,488],"class_list":["post-397","post","type-post","status-publish","format-standard","hentry","category-atl","category-seriously","category-source","tag-atl","tag-source"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=397"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/397\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}