专注于模态对话框(MFC) [英] Focus on Modal Dialog (MFC)
问题描述
我创建了这样的模态对话框:
I create modal dialog like this :
CDialog dlg;
dlg.DoModal();
但是当窗口打开时,我可以访问我的程序的后台窗口(移动它们并关闭它们),但是只需要关注我的窗口。 (我认为模态对话不应该这样)
but when window opens I can access background windows of my program (move them and close them) but I need focus only on my curent window. (I think modal dialog shouldn't behave like this)
我该怎么做?
编辑:
似乎我发现了这个行为的原因:在打开我的对话框之前,我在CMyDlg :: OnInitDialog()函数中打开另一个模态对话框当我评论这个时,我的对话再次变成了模态。但是如何解决这个问题?
It seems I found the reason of this behavior: before open my dialog,I open another modal dialog in CMyDlg::OnInitDialog() function, when I comment this,my dialog again became modal. But how to solve this problem?
描述问题的一些代码:
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();
//...
}
推荐答案
可以通过指定对话框的父窗口来解决您的问题,您可以通过将此指针传递给每个对话框类的构造函数,如代码所示。
you can solve your problem by specifying parent window for the dialog, you can do by passing this pointer in constructor of each dialog class as shown in code .
void CMyView::OnSomeButtonPress()
{
CMyDlg dlg(this);
dlg.DoModal();
}
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//some init here...
CSettingsDlg dlg(this);
dlg.DoModal();
//...
}
这篇关于专注于模态对话框(MFC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!