简体   繁体   English

单击确定后继续MFC对话框

[英]MFC dialog box continue after pressing ok

I have a custom dialog message box that pops-up when a edit control in my main dialog has wrong data. 我有一个自定义对话框消息框,当主对话框中的edit control中的数据错误时会弹出该对话框。

CDlgError dlgError = new CDlgError(this);
dlgError.Create(CDlgError::IDD, this);
dlgError.m_staticMessage.SetWindowTextA("Error message!");
dlgError.ShowWindow(SW_SHOW);

//more code

I want the rest of the code to be executed only after i press an OK button in my CDlgError pop-up dialog. 我希望仅在按下CDlgError弹出对话框中的“ OK button后才能执行其余代码。 How can i do that? 我怎样才能做到这一点?

Use DoModal instead of Create and ShowWindow to show your error dialog. 使用DoModal而不是CreateShowWindow来显示错误对话框。 eg 例如

CDlgError dlgError = new CDlgError(this);
dlgError.m_strMessage = "Error message!";
dlgError.DoModal();

As you can see from the code you'll need to pass in the text and THEN set your message label inside CDlgError::OnInitDialog because the control won't be initialized before going modal. 从代码中可以看到,您需要传递文本,然后在CDlgError::OnInitDialog内设置消息标签,因为在进行模式化之前不会初始化控件。

You are creating a dialog using Create which shows a modalless dialog(you can click on other parts of application even dialog is open). 您正在使用Create一个显示无模态对话框的对话框(即使对话框打开,也可以单击应用程序的其他部分)。 You requirement is for modal dialog where you can not click on any part of application until this dialog is closed. 您需要模态对话框,在该对话框中,除非关闭此对话框,否则您无法单击应用程序的任何部分。 To do this use DoModal function instead of create. 为此,请使用DoModal函数而不是create。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM