Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual c++ 聚焦于模态对话框(MFC)_Visual C++_User Interface_Mfc_Dialog_Modal Dialog - Fatal编程技术网

Visual c++ 聚焦于模态对话框(MFC)

Visual c++ 聚焦于模态对话框(MFC),visual-c++,user-interface,mfc,dialog,modal-dialog,Visual C++,User Interface,Mfc,Dialog,Modal Dialog,我创建的模态对话框如下所示: CDialog dlg; dlg.DoModal(); 但当窗口打开时,我可以访问程序的背景窗口(移动并关闭它们),但我只需要关注当前窗口。(我认为模态对话框不应该这样做) 我该怎么做 编辑: void CMyView::OnSomeButtonPress() { CMyDlg dlg; dlg.DoModal(); } BOOL CMyDlg::OnInitDialog() { CDialog::OnInitDialog();

我创建的模态对话框如下所示:

CDialog dlg;
dlg.DoModal();
但当窗口打开时,我可以访问程序的背景窗口(移动并关闭它们),但我只需要关注当前窗口。(我认为模态对话框不应该这样做)

我该怎么做

编辑:

void CMyView::OnSomeButtonPress() 
{
    CMyDlg dlg;
    dlg.DoModal();
}

BOOL CMyDlg::OnInitDialog() 
{
    CDialog::OnInitDialog();

    //some init here...


    //new modal dialog here (if comment this CMyDlg works as modal)
    CSettingsDlg dlg;
    dlg.DoModal();

    //...
 }
似乎我找到了这种行为的原因:在打开对话框之前,我在CMyDlg::OnInitDialog()函数中打开了另一个模态对话框,当我对此进行注释时,我的对话框再次变成模态对话框。但如何解决这个问题呢

一些描述问题的代码:

void CMyView::OnSomeButtonPress() 
{
    CMyDlg dlg;
    dlg.DoModal();
}

BOOL CMyDlg::OnInitDialog() 
{
    CDialog::OnInitDialog();

    //some init here...


    //new modal dialog here (if comment this CMyDlg works as modal)
    CSettingsDlg dlg;
    dlg.DoModal();

    //...
 }

不能从OnInitDialog方法中使用对话框,也不能从OnInitDialog方法调用的任何函数中使用对话框。您必须从其他位置使用CSettingsDlg的DoModal()

大概是这样的:

void CMyView::OnSomeButtonPress() 
{
    //new modal dialog here (if comment this CMyDlg works as modal)
    CSettingsDlg dlgSettings;
    dlgSettings.DoModal();

    ...

    CMyDlg dlg;
    dlg.DoModal();
}

BOOL CMyDlg::OnInitDialog() 
{
    CDialog::OnInitDialog();

    //some init here...

    //...
 }

不能从OnInitDialog方法中使用对话框,也不能从OnInitDialog方法调用的任何函数中使用对话框。您必须从其他位置使用CSettingsDlg的DoModal()

大概是这样的:

void CMyView::OnSomeButtonPress() 
{
    //new modal dialog here (if comment this CMyDlg works as modal)
    CSettingsDlg dlgSettings;
    dlgSettings.DoModal();

    ...

    CMyDlg dlg;
    dlg.DoModal();
}

BOOL CMyDlg::OnInitDialog() 
{
    CDialog::OnInitDialog();

    //some init here...

    //...
 }

您可以通过为对话框指定父窗口来解决问题,也可以通过在每个对话框类的构造函数中传递此指针来解决问题,如代码所示

void CMyView::OnSomeButtonPress()
{
    CMyDlg dlg(this);
    dlg.DoModal();
}

BOOL CMyDlg::OnInitDialog() 
{
     CDialog::OnInitDialog();

    //some init here...
    CSettingsDlg dlg(this);
    dlg.DoModal();

    //...
 }

您可以通过为对话框指定父窗口来解决问题,也可以通过在每个对话框类的构造函数中传递此指针来解决问题,如代码所示

void CMyView::OnSomeButtonPress()
{
    CMyDlg dlg(this);
    dlg.DoModal();
}

BOOL CMyDlg::OnInitDialog() 
{
     CDialog::OnInitDialog();

    //some init here...
    CSettingsDlg dlg(this);
    dlg.DoModal();

    //...
 }

这听起来像是父窗口问题。可能由于某种原因,对话框的父窗口不正确。如果看不到更多的代码,很难判断发生了什么。它是什么类型的MFC应用程序?基于对话?MDI,SDI?是MDI,什么是“父窗口问题”?好了,现在清楚了。如果你问问题,尽量提供最多的信息。否则你将得不到答案,你将得到错误的答案,或者人们会要求你提供更多信息(就像我一样)。这听起来像是家长窗口的问题。可能由于某种原因,对话框的父窗口不正确。如果看不到更多的代码,很难判断发生了什么。它是什么类型的MFC应用程序?基于对话?MDI,SDI?是MDI,什么是“父窗口问题”?好了,现在清楚了。如果你问问题,尽量提供最多的信息。否则你将得不到答案,你将得到错误的答案,或者人们会要求你提供更多信息(就像我一样)。