Reputation: 77
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();
}
Upvotes: 0
Views: 714
Reputation: 77
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.
Upvotes: 0
Reputation: 12731
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
Upvotes: 0