{"id":596,"date":"2015-12-20T20:37:28","date_gmt":"2015-12-20T12:37:28","guid":{"rendered":"http:\/\/www.withonly.com\/?p=596"},"modified":"2015-12-20T20:37:28","modified_gmt":"2015-12-20T12:37:28","slug":"win32-%e7%a8%8b%e5%ba%8f%e7%aa%97%e4%bd%93%e5%b1%85%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/blog.5danyuan.com\/?p=596","title":{"rendered":"win32 \u7a0b\u5e8f\u7a97\u4f53\u5c45\u4e2d"},"content":{"rendered":"<p>C#\u5bf9\u4e8e\u7a97\u4f53\u5c45\u4e2d\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u8981\u7b80\u5355\u8bbe\u7f6e\u4e00\u4e2a\u5c5e\u6027\u5c31\u53ef\u4ee5\u4e86\uff0c\u4f46\u662f\u5bf9\u4e8eC++\uff0c\u8fd8\u9700\u8981\u989d\u5916\u7684\u5199\u70b9\u4ee3\u7801\u3002\u4e0b\u9762\u662f\u8863\u670d\u81ea\u5df1\u6d17\u5206\u4eab\u7684\u4ee3\u7801\uff0c\u53ef\u4ee5\u76f4\u63a5\u62f7\u8d1d\u5230\u9879\u76ee\u4e2d\u3002<\/p>\n<p>inline static BOOL CenterWindow(HWND hwndWindow,bool isDesktopParent = true)<br \/>\n{<br \/>\nHWND hwndParent;<br \/>\nRECT rectWindow, rectParent;<\/p>\n<p>hwndParent = isDesktopParent ? GetDesktopWindow() : GetParent(hwndWindow);<\/p>\n<p>\/\/make the window relative to its parent<br \/>\nif (hwndParent != nullptr)<br \/>\n{<br \/>\nGetWindowRect(hwndWindow, &amp;rectWindow);<br \/>\nGetWindowRect(hwndParent, &amp;rectParent);<\/p>\n<p>int nWidth = rectWindow.right &#8211; rectWindow.left;<br \/>\nint nHeight = rectWindow.bottom &#8211; rectWindow.top;<\/p>\n<p>int nX = ((rectParent.right &#8211; rectParent.left) &#8211; nWidth) \/ 2 + rectParent.left;<br \/>\nint nY = ((rectParent.bottom &#8211; rectParent.top) &#8211; nHeight) \/ 2 + rectParent.top;<\/p>\n<p>int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);<br \/>\nint nScreenHeight = GetSystemMetrics(SM_CYSCREEN);<\/p>\n<p>\/\/make sure the window never moves outside of the screen<br \/>\nif (nX &lt; 0) nX = 0;<br \/>\nif (nY &lt; 0) nY = 0;<br \/>\nif (nX + nWidth &gt; nScreenWidth) nX = nScreenWidth &#8211; nWidth;<br \/>\nif (nY + nHeight &gt; nScreenHeight) nY = nScreenHeight &#8211; nHeight;<\/p>\n<p>MoveWindow(hwndWindow, nX, nY, nWidth, nHeight, FALSE);<\/p>\n<p>return TRUE;<br \/>\n}<\/p>\n<p>return FALSE;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C#\u5bf9\u4e8e\u7a97\u4f53\u5c45\u4e2d\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u8981\u7b80\u5355\u8bbe\u7f6e\u4e00\u4e2a\u5c5e\u6027\u5c31\u53ef\u4ee5\u4e86\uff0c\u4f46\u662f\u5bf9\u4e8eC++\uff0c\u8fd8\u9700\u8981\u989d\u5916\u7684\u5199\u70b9\u4ee3\u7801\u3002\u4e0b\u9762\u662f\u8863\u670d\u81ea\u5df1\u6d17 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[234,3],"tags":[120,264],"class_list":["post-596","post","type-post","status-publish","format-standard","hentry","category-c","category-a-short-word","tag-c-sharp","tag-264"],"_links":{"self":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=596"}],"version-history":[{"count":0,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/596\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}