在运行时将无模式对话框转换为模式对话框 [英] Convert a modeless dialog to modal at runtime

查看:138
本文介绍了在运行时将无模式对话框转换为模式对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话框(派生自CDialog的类),可以用两种不同的方式(版本模式和编程模式)使用该对话框.

I have a dialog (CDialog derived class) that can be used in two different ways (edition mode and programming mode).

打开对话框以在编程模式下使用时,它是一个无模式对话框,用于修改主视图(一种工具栏).在编辑模式下打开对话框时,用户可以更改对话框本身的配置,在这种情况下,它是模式对话框.

When the dialog is open to be used in programming mode it is a modeless dialog that it is used for modifying the main view (kind of a toolbar). When it is open in edition mode the user can change the configuration of the dialog itself and in this case it is a modal dialog.

现在,它们是两个不同的对话框,几乎没有什么区别,我想只需要一个对话框,让用户只需按对话框中的一个按钮即可在编程模式和编辑模式之间进行切换.

Right now they are two different dialogs with few differences and I would like to have just want dialog and let the user change between programming mode and edition mode just by pressing a button in the dialog.

因此,我需要在运行时将无模式对话框转换为模式对话框,反之亦然.有没有办法做到这一点?

So I need to convert the modeless dialog in a modal dialog and vice versa at runtime. Is there a way to achive that?

谢谢.

推荐答案

也许有人可能会对将来做类似的事情感兴趣,这就是我最终做到的方式:

As maybe someone could be interested in doing something similar in the future, this is the way I eventually did it:

我使用主机的这两个功能:CMainFrame::BeginModalState()CMainFrame::EndModalState().

I use this two functions of main frame: CMainFrame::BeginModalState() and CMainFrame::EndModalState().

这些功能的问题与禁用父窗口相同.您想要使其成为模态的窗口也被禁用.但是解决方案很简单,只需在调用BeginModalState之后重新启用窗口即可.

The problem with these functions is the same that with disabling the parent window. The window you want to make modal also gets disabled. But the solution is easy, just re-enable the window after calling BeginModalState.

void CMyDialog::MakeModal()
{
   //disable all main window descendants
   AfxGetMainWnd()->BeginModalState();

   //re-enable this window
   EnableWindow(TRUE);
}

void CMyDialog::MakeModeless()
{
   //enable all main window descendants
   AfxGetMainWnd()->EndModalState();
}

感谢您的帮助.

这篇关于在运行时将无模式对话框转换为模式对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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