如何使用 CPropertyPage::OnOk() 防止 MFC 对话框窗口关闭?
我正在开发一个 C++ 项目,并且有一个 CPropertyPage::OnOk()
方法。
我希望发生的是,当用户单击确定或应用时,程序将执行检查,如果检查错误,它将禁止窗口关闭。
我该如何阻止窗口关闭?
我尝试过简单的返回,但没有成功。
例如:
void CApptEditGen::OnOK()
{
if ( prealloc(&m_ai->apapallocate) || Dummy_aftalloc(m_ai) == REDO ) {
m_pCtl_ApptEdit_Units->SetFocus();
m_pCtl_ApptEdit_Units->SetWindowText("");
return;
}
CPropertyPage::OnOK();
}
I'm working on a C++ project and have a CPropertyPage::OnOk()
method.
What I'd like to happen is when the user clicks Ok or Apply, the program will perform a check, if the check is wrong, it'll supress the window from closing.
How would I go about to supressing the window from closing?
I've tried a simple return but no go.
For example:
void CApptEditGen::OnOK()
{
if ( prealloc(&m_ai->apapallocate) || Dummy_aftalloc(m_ai) == REDO ) {
m_pCtl_ApptEdit_Units->SetFocus();
m_pCtl_ApptEdit_Units->SetWindowText("");
return;
}
CPropertyPage::OnOK();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用以下命令检查值 A > 是否为然后值 B 返回 0 以停止关闭!
Used the following to check if value A > value B then return 0 to stop from closing!
简单的返回就可以解决问题,如下面来自 MSDN 上的此页面,其中描述了 CDialog 的 OnOK() 函数(CPropertyPage 从中派生):
您绝对确定已正确重写 CPropertyPage 上的 OnOK() 吗?如果没有,则将调用默认的 CPropertyPage::OnOK,这将按照您的描述关闭窗口。
A simple return should do the trick, as demonstrated by the code snippet below from this page on MSDN, which describes the OnOK() function of CDialog (from which CPropertyPage is derived):
Are you absolutely sure you've correctly overriden OnOK() on CPropertyPage? If not then the default CPropertyPage::OnOK will be called, which will close the window as you describe.