关闭Dialog mfc的onClose事件的无模式或模态对话框 [英] Close Modeless or Modal dialogues onClose event of Dialog mfc

查看:396
本文介绍了关闭Dialog mfc的onClose事件的无模式或模态对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的基于MFC对话的应用程序中,一种情况是首先打开模型对话框并单击该对话框的一个按钮事件,它打开包含Initinstance和OnInitDialog方法的主对话框,所以我的问题是每当我关闭这个第一个对话框onCancel事件发生,在那个事件我调用PostQuitMessage(),它关闭应用程序,但稍微显示下一个窗口然后关闭。我认为这个方法是错误的!我还有其他方法吗?请建议!

提前致谢!!

In my MFC dialogue based application one situation is that first I open model dialog and click event of one of button of this dialog,it open main dialog which contains Initinstance and OnInitDialog method in it,so my question is whenever I close this first dialog onCancel event occur and in that event I called PostQuitMessage(),it closes application but slightly show next window and then close.I think this method is wrong!I any another method to do that?please suggest!
Thanks in advance!!

推荐答案

如果您需要在主对话框之前显示的启动对话框,只需在 InitInstance()并在取消时返回:

If you need a start dialog that is shown before your main dialog, just show this dialog from within InitInstance() and return upon Cancel:
BOOL CMyApp::InitInstance()
{
    // Common initialization

    // Show start dialog
    CStartDlg StartDlg;
    if (StartDlg.DoModal() == IDCANCEL)
        return FALSE;

    // Show the main dialog
    CMainDlg MainDlg;
    m_pMainWnd = &MainDlg;
    MainDlg.DoModal();
    return FALSE;
}



如果需要在启动对话框和应用程序之间传递一些数据,可以将指针传递给 CMyApp class。






If you need to pass some data between the start dialog and your application, you can pass a pointer to your CMyApp class.


BOOL CMyApp::InitInstance()
{
    // Common initialization

    // Create the main dialog instance and assign it to m_pMainWnd
    CMainDlg MainDlg;
    m_pMainWnd = &MainDlg;

    // Show start dialog
    CStartDlg StartDlg;
    if (StartDlg.DoModal() == IDCANCEL)
        return FALSE;

    // Show the main dialog
    MainDlg.DoModal();
    return FALSE;
}

void CStartDlg::OnOK()
{
    // Pass data to main dialog members here.
    // Note that the dialog window itself is not created yet.
    // So access only CMainDlg specific member variables 
    //  (no CWnd base class members).
    CMainDlg* pMainDlg = static_cast<CMainDlg*>(AfxGetApp()->m_pMainWnd);
//  pMainDlg->SomeVar = SomeValue;
    CDialog::OnOK();
}


我的设计听起来不对劲;为什么需要一个对话框来打开主对话框?对话框应用程序应该只需要一个在应用程序启动时自动打开的对话框。它可能在其生命周期中使用其他子对话,但这就是必要的。
Your design sounds wrong to me; why do you need a dialog to open your main dialog? A dialog application should only need a single dialog which opens automatically when the application starts. It may use other child dialogs during its lifetime but that is all that would be necessary.


这篇关于关闭Dialog mfc的onClose事件的无模式或模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆