I have just encountered an issue with CPropertyPage.
I have been trying to use the OnOK handler to do some validation:
void CCalendarSettingsGooglePage::OnOK()
{
bool bHandle = false;
UpdateData(TRUE);
// AJT v20.2.0 — We need to pass "true" so that the error message will display!
if (ValidSettings(true))
{
bHandle = true;
SaveSettings();
}
if (bHandle)
CMFCPropertyPage::OnOK();
}
The problem is, the sheet still closes down. I had hoped that preventing the CMFCPropertyPage::OnOK would have stopped the sheet closing. But it doesn't.
I understand from here that the sheet's OnOK is making a EndDialog(IDOK) call. But i don't want to complicate my sheet. The testing is here in this page. so I need a was for the sheet to know if it should close or not when user clicks the OK button.
You need to override the
OnCommandhandler of your property page's parent property sheet class and intercept the clicks for theIDOKcommand (which will be given in thewParamparameter). If you do not call the base classOnCommandbut still returnTRUEto indicate that your have handled the command, then the property sheet will not close:Note that I have assumed your parent is derived from
CMFCPropertySheet, but the same works for the 'older'CPropertySheet.