如果有错误,CPropertyPage 对话 OnOk 不应关闭对话 [英] CPropertyPage dialogue OnOk should not close the dialogue if there is an error

查看:47
本文介绍了如果有错误,CPropertyPage 对话 OnOk 不应关闭对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个继承自 CPropertyPage 类的类.我有一个 OnOk() 方法和一个 OnKillActive() 方法.每当我在对话上按 Ok 时.OnKillActive() 被调用,但 OnOk() 从未被调用.问题取决于我不想在按下 Ok 时关闭对话的条件.但是对话在按下 Ok 后就结束了.

I have a class which inherits from CPropertyPage class. I have a OnOk() method and a OnKillActive() method. Whenever I press Ok on the dialogue. OnKillActive() gets called but OnOk() is never called. The problem is depending on a condition I do not want to close the dialogue on pressing Ok. But the dialogue is closing on pressing Ok.

当我按下确定"时,如何防止对话框关闭?

How do I prevent the dialogue from closing when I press Ok?

代码:

In MyClass.h:
    class MyClass : public CPropertyPage {
    }

In MyClass.cpp:
    void MyClass::OnOK(){
        if (condition true) {
            return; // This should prevent the dialogue from closing but still      the dialogue closes
        }
        return CPropertyPage::OnOk();
    }

    BOOL MyClass::OnKillActive() {
        if (condition true) {
            CDialog::DoModal();
            return FALSE; // This should prevent the dialogue from closing but   still the dialogue closes
        }
        return CPropertyPage::OnKillActive();
    }

推荐答案

其实在 PropertySheet 类的 OnClickedOk() 函数中,有一个 EndDialog(IDOK).这就是为什么每次按下 Ok 时它都会关闭.

Actually in the OnClickedOk() function of the PropertySheet class, there was an EndDialog(IDOK). This is why it was closing everytime when Ok was pressed.

我只是在 EndDialog() 之前进行了条件检查,结果奏效了.感谢您的回复.

I just gave a condition check before EndDialog() and it worked. Thanks for your reply.

这篇关于如果有错误,CPropertyPage 对话 OnOk 不应关闭对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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