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

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

问题描述

我有一个对话框(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天全站免登陆