Convert a modeless dialog to modal at runtime(在运行时将无模式对话框转换为模式)
问题描述
我有一个对话框(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();
}
感谢您的帮助.
这篇关于在运行时将无模式对话框转换为模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在运行时将无模式对话框转换为模式


基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01