简体   繁体   中英

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

I am not sure if you can call CDialog::DoModal(); as your property page is not closed yet.

When this event( OnKillActive() ) occurs your property page is inactive . But your property page still exists and the data in the property page also exists for validation.

To bring your page back, just set the focus in one of the dialog item. Use " GetDlgItem " to get an object and set the focus using " SetFocus "

An example is available here.

https://msdn.microsoft.com/en-us/library/2122ct0z.aspx

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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