mfccdialogcpropertysheet

CPropertyPage dialogue OnOk should not close the dialogue if there is an error


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?

Code:

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();
    }

Solution

  • 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.

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