在一个单文档中打开一个非模式对话框,想在关闭非模式对话框关闭前,把单文档对窗口设置为最大话,但是,却GetParent()得不到父窗口。请问各位有没有这方面的问题过啊。代码如:
void CDlg::OnClose() 
{
CMainFrame * frame=(CMainFrame *)GetParent();
frame->ShowWindow(SW_SHOWMAXIMIZED);
CDialog::OnClose();
}

解决方案 »

  1.   

    试试这样:
    void CDlg::OnClose() 
    {
    HWND hParent = ::GetParent(m_hWnd);
    ::ShowWindow(hParent, SW_MAXIMIZE);
    CDialog::OnClose();
    }
      

  2.   

    CMainFrame::CMainFrame()
    {
    m_dlg.Create(IDD_COLOR,this);
    }
    它是框架类的成员.
      

  3.   

    在WIN32里没做过,在MFC里可以这样实现:参考一下
    void CDialog1::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    CMainFrame *pFrame=(CMainFrame*)AfxGetMainWnd();
    pFrame->ShowWindow(SW_MAXIMIZE);
    CDialog::OnOK();
    }
      

  4.   

    如果父窗口没有问题话,跟踪一下看这个OnClose函数是否执行了?
    1. 是否添加了消息映射 ON_WM_CLOSE() ?
    2. OnClose改成OnCancel试试
      

  5.   

    void CDlg::OnClose() 
    {
    HWND hParent = ::GetParent(m_dlg.m_hWnd);
    ::ShowWindow(hParent, SW_MAXIMIZE);
    CDialog::OnClose();
    }应该没问题啊,按机器人的说法来检查是否调用...
      

  6.   

    错了this->m_hWnd呵,一样滴这种方法应该不错,应该是没有调用...断点调试
      

  7.   

    得到框架窗口用AfxGetMainWnd()就行了。你的對話框窗口應該不是在CMainFrame類中創建的吧,所以父窗口不一定是框架窗口。
      

  8.   

    void CDialog1::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    CMainFrame *pFrame=(CMainFrame*)AfxGetMainWnd();
    pFrame->ShowWindow(SW_MAXIMIZE);
    CDialog::OnOK();
    }
    绝对可以!
      

  9.   

    OK了,就是只能用那个AfxGetMainWnd(),
    GetParent()只能得到这个Modeless dialog自己的框架窗口而已.
    什么GetParent(),GetTopLevelOwner(),GetTopWindow()等这些个CWnd成员函数都一样.
    开始发分了....谢谢大家了.....