{"id":227,"date":"2009-01-08T15:31:30","date_gmt":"2009-01-08T07:31:30","guid":{"rendered":"http:\/\/www.cgdev.net\/blog\/?p=227"},"modified":"2023-04-25T12:02:24","modified_gmt":"2023-04-25T04:02:24","slug":"%e7%aa%97%e5%8f%a3%e6%97%a0%e6%b3%95%e4%bf%ae%e6%94%b9%e5%85%b6owner","status":"publish","type":"post","link":"https:\/\/www.cgdev.net\/blog\/227.html","title":{"rendered":"\u7a97\u53e3\u65e0\u6cd5\u4fee\u6539\u5176Owner"},"content":{"rendered":"<p>API\u51fd\u6570GetWindow(hWnd, GW_OWNER)\u53ef\u4ee5\u5f97\u5230hWnd\u7684owner\u7a97\u53e3, GetParent(hWnd)\u4e5f\u53ef\u4ee5\u5f97\u5230parent\u6216\u8005owner,<br \/>\n\u4f46\u5fae\u8f6f\u600e\u4e48\u4e0d\u505a\u4e2aSetWindow\u8fd9\u6837\u7684API\u51fd\u6570\u6765\u771f\u6b63\u4fee\u6539\u5176owner\u5462?, MFC\u867d\u7136\u6709SetOwner\u51fd\u6570, \u4f46\u67e5\u4e86\u4e00\u4e0b\u6e90\u7801,<br \/>\n\u53d1\u73b0\u53ea\u662f\u628aowner\u7a97\u53e3\u4fdd\u5b58\u8d77\u6765\u800c\u5df2, \u5e76\u4e0d\u662f\u50cfparent\/child\u90a3\u6837\u5728\u7a97\u53e3\u7ea7\u522b\u5efa\u7acb\u4e86\u4e00\u4e2a\u94fe\u63a5\u5173\u7cfb, \u90c1\u95f7<\/p>\n<pre lang='a_c'>\r\nvoid CWnd::SetOwner(CWnd* pOwnerWnd)\r\n{ \r\n   m_hWndOwner = pOwnerWnd != NULL ? pOwnerWnd->m_hWnd : NULL;\r\n}\r\n\r\nCWnd* CWnd::GetOwner() const\r\n{\r\n   return m_hWndOwner != NULL ? CWnd::FromHandle(m_hWndOwner) : GetParent();\r\n}\r\n<\/pre>\n<p>\u518d\u6765\u770b\u770bVC2008\u4e2d\u7684\u4e00\u4e2a\u9690\u85cf\u51fd\u6570, \u8be5\u51fd\u6570\u5728MSDN\u4e2d\u6ca1\u6709\u6587\u6863\u652f\u6301<\/p>\n<pre lang='a_c'>\r\nHWND AFXAPI AfxGetParentOwner(HWND hWnd)\r\n{\r\n    \/\/ check for permanent-owned window first\r\n    CWnd* pWnd = CWnd::FromHandlePermanent(hWnd);\r\n    if (pWnd != NULL)\r\n       return pWnd->GetOwner()->GetSafeHwnd();\r\n\r\n    \/\/ otherwise, return parent in the Windows sense\r\n    return (::GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) ?\r\n        ::GetParent(hWnd) : ::GetWindow(hWnd, GW_OWNER);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>API\u51fd\u6570GetWindow(hWnd, GW_OWNER)\u53ef\u4ee5\u5f97\u5230hWnd\u7684owner\u7a97\u53e3, GetParent(hWnd)\u4e5f\u53ef\u4ee5\u5f97\u5230parent\u6216\u8005owner, \u4f46\u5fae\u8f6f\u600e\u4e48\u4e0d\u505a\u4e2aSetWindow\u8fd9\u6837\u7684API\u51fd\u6570\u6765\u771f\u6b63\u4fee\u6539\u5176owner\u5462?, MFC\u867d\u7136\u6709SetOwner\u51fd\u6570, \u4f46\u67e5\u4e86\u4e00\u4e0b\u6e90\u7801, \u53d1\u73b0\u53ea\u662f\u628aowner\u7a97\u53e3\u4fdd\u5b58\u8d77\u6765\u800c\u5df2, \u5e76\u4e0d\u662f\u50cfparent\/child\u90a3\u6837\u5728\u7a97\u53e3\u7ea7\u522b\u5efa\u7acb\u4e86\u4e00\u4e2a\u94fe\u63a5\u5173\u7cfb, \u90c1\u95f7 void CWnd::SetOwner(CWnd* pOwnerWnd) { m_hWndOwner = pOwnerWnd != NULL ? pOwnerWnd->m_hWnd : NULL; } CWnd* CWnd::GetOwner() const { return m_hWndOwner != NULL ? CWnd::FromHandle(m_hWndOwner) : GetParent(); } \u518d\u6765\u770b\u770bVC2008\u4e2d\u7684\u4e00\u4e2a\u9690\u85cf\u51fd\u6570, \u8be5\u51fd\u6570\u5728MSDN\u4e2d\u6ca1\u6709\u6587\u6863\u652f\u6301 HWND AFXAPI AfxGetParentOwner(HWND hWnd) { \/\/ check for permanent-owned window first CWnd* pWnd = CWnd::FromHandlePermanent(hWnd); if (pWnd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-227","post","type-post","status-publish","format-standard","hentry","category-cpp"],"_links":{"self":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts\/227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/comments?post=227"}],"version-history":[{"count":0,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts\/227\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/media?parent=227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/categories?post=227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/tags?post=227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}