CWnd::GetSafeOwnerResCall this member function to retrieve the owner window that should be used for dialog boxes or other modal windows. The safe owner is the first non-child parent window of pParentWnd. If pParentWnd is NULL, the thread’s main window (retrieved via AfxGetMainWnd) is used to find an owner
CDlg1的类中DoModal默认父窗口就是CDlg1
派生类对话框的构造函数如下:
CMyDlg::CMyDlg():CDialog(CMyDlg::IDD)
{
m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
从而调用基类构造函数
CDialog::CDialog(UINT nIDTemplate,CWnd * pParentWnd=NULL)
{
m_pParentWnd=pParentWnd;
m_lpszTemplateName=MAKEINTRESOURECE(nIDTemplate);
m_nIDhelp=nIDTemplate;
}
第二、调用DoModal()
代码简述如下:
{
//略
HWND hWndParent=PreModal() //这行代码的意思是好像找到了父类窗口的句柄,看看是它是怎么
//找到的。
//略
}CDialog::PreModal()
{ //略
//下面调用函数的第一个参数似乎有问题,在前面m_pParentWnd已经被赋了空值,这里怎么
能调用GetSafeHwnd()函数呢?请高人指点。(在线等候)
HWND hWnd = CWnd::GetSafeOwner_(m_pParentWnd->GetSafeHwnd(), &m_hWndTop); return hWnd;
}
hWnd = AfxGetMainWnd()->GetSafeHwnd();
会设为主程序的窗口句柄具体函数在CWnd::GetSafeOwner_里