按条件打开对话框 [英] open dialog by condition

查看:81
本文介绍了按条件打开对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想创建一个仅在条件发生时打开的对话框.
在对话框中,我将具有确定"按钮和取消"按钮,并且仅在用户按下确定"时我才想继续.

例如:

Hello,

I want to make a dialog that get opened only if a condition occurs.
in the dialog, I will have ok button and cancel button, and I want to continue only if user presses OK.

for example:

if (condition)
{
 open dialog.
 if user clicked OK, do something
 else do something else
}



如何使用MFC进行操作?

感谢



How can I do it using MFC?

Thanks

推荐答案

一目了然,您需要一个 modal 对话框.我认为有 ^ ].
In a glance, you need a modal dialog. I think there''s a plethora of tutorials[^] on the web.


通常这是通过调用对话框的DoModal()并使用返回值来完成的:
This is usually done calling DoModal() of your dialog and using the return value:
if (condition)
{
    CMyDialog Dlg;
    if (Dlg.DoModal() == IDOK)
    {
        // OK pressed
    }
    else
    {
        // Dialog cancelled
    }
}


这很简单...

如果只需要显示信息,则使用AfxMessageBox()(易于使用),如果需要对话框,则创建一个从CDialog MFC类派生的对话框,并使用CDialog::DoModal()方法对话框(如果要使其成为模态,要使其变为无模态,请先创建它,然后使用ShowWindow()调出它).

覆盖CDialog::OnInitDialog()以更新对话框中可能使用的任何控件(请勿在构造函数中执行此操作!这是一个常见错误,目前尚未创建控件).
This is trivial...

If you only need to display information, use a AfxMessageBox() (it''s easy to use), if you need a dialog, then make a dialog derived from the CDialog MFC class and use the CDialog::DoModal() method to bring up the dialog (this is if you want to make it modal, to make it modeless, create it first then bring it up using ShowWindow()).

Override CDialog::OnInitDialog() to update any controls you may be using within the dialog (DO NOT do this in the constructor! This is a common mistake, the controls have not been created at this point).


这篇关于按条件打开对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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