在运行时将无模式对话框转换为模式

编程入门 行业动态 更新时间:2024-10-28 04:28:26
本文介绍了在运行时将无模式对话框转换为模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个对话框(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(); }

感谢您的帮助.

更多推荐

在运行时将无模式对话框转换为模式

本文发布于:2023-11-12 07:54:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580933.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   转换为   对话框   时将

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!