关于GetParent()返回值?
按照说明这个函数返回其父窗口对象,但是我在实际使用中却发现不对额。建了一个基于对话框的程序,主窗口(即主对话框)创建一个非模态对话框1,该非模态对话框1又创建一个非模态对话框2。我在非模态对话框2中调用GetParent(),按说明应该返回非模态对话框1指针,但是我调试发现其返回的是主窗口(即主对话框对象),又尝试调用::GetParent(m_hWnd),仍然返回主窗口句柄。
如果直接在非模态对话框2中使用m_pParentWnd,该指针就是正确的非模态对话框1.求解释额~
对话框1是在主对话框中创建的,对话框2是在对话框1创建的,创建时都传入this。
[解决办法]
那肯定,不是child,哪来的parent?
CWnd::GetParent
CWnd* GetParent( ) const;
Return Value
Identifies the parent window if the member function is successful. Otherwise, the value is NULL, which indicates an error or no parent window.
The returned pointer may be temporary and should not be stored for later use.
Remarks
Call this function to get a pointer to a child window’s parent window (if any). The GetParent function returns a pointer the immediate parent. In contrast, the GetParentOwner function returns a pointer to the most immediate parent or owner window that is not a child window (does not have the WS_CHILD style). If you have a child window within a child window GetParent and GetParentOwner return different results.