API函数GetWindow(hWnd, GW_OWNER)可以得到hWnd的owner窗口, GetParent(hWnd)也可以得到parent或者owner,
但微软怎么不做个SetWindow这样的API函数来真正修改其owner呢?, MFC虽然有SetOwner函数, 但查了一下源码,
发现只是把owner窗口保存起来而已, 并不是像parent/child那样在窗口级别建立了一个链接关系, 郁闷
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(); }
再来看看VC2008中的一个隐藏函数, 该函数在MSDN中没有文档支持
HWND AFXAPI AfxGetParentOwner(HWND hWnd) { // check for permanent-owned window first CWnd* pWnd = CWnd::FromHandlePermanent(hWnd); if (pWnd != NULL) return pWnd->GetOwner()->GetSafeHwnd(); // otherwise, return parent in the Windows sense return (::GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) ? ::GetParent(hWnd) : ::GetWindow(hWnd, GW_OWNER); }
Leave a Reply