Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 674
  • Last Modified:

CPropertyPage

Hi!

I have a problem using CPropertyPage.
I want to perform something ONLY when the user presses OK, but not when he/she presses Apply. I've tried overriding OnApply, OnOk and OnKillActive, but they occur at different times no matter which button I pressed.
Iv'e also tried to override OnNotify, but I dont know which parameter to check for which ID to know if the propertypage's defualt OK-button was pressed.
So, how should I do this?
Thanks!
 
0
Scattan
Asked:
Scattan
  • 4
  • 3
  • 3
1 Solution
 
ZoppoCommented:
Hi Scattan,

problem seems that CPropertyPage::OnOK() calls OnApply()
you can override OnApply() and OnOK() and use a flag like this:

// in .h file
class CMyPropPage : public CPropertyPage
{
 ...
 bool m_bApplyPressed;
 ...
}

// in .cpp file
CMyPropPage::CMyPropPage()...
{
 m_bApplyPressed = false;
 ...
}

CMyPropPage::OnOK()
{
 if ( !m_bApplyPressed )
 {
  // do here what you want only to be done with OK
 }
 CPropertyPage::OnOK();
}

BOOL CMyPropPage::OnApply()
{
 m_bApplyPressed = true;
 BOOL bRet = CPropertyPage::OnApply();
 m_bApplyPressed = false;

 return bRet;
}

hope that helps,

ZOPPO
0
 
ScattanAuthor Commented:
Hi Zoppo!

Thanks, but in CPropertyPage the OnApply-function is called before OnOk wether you pressed the ok-button or the Apply-button, it's the same "calling order".
So I have to do something else, or the m_bApplyPressed will allways be true when I reach OnOk.

Any other suggestions?

How do I get hold of the messagehandles for the buttons in the propertypage?

0
 
ScattanAuthor Commented:
(I ment the default-buttons ofcourse, the ones I cannot add myself Apply,OK,Cancel & Help)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZoppoCommented:
ok, sorry for delay, wasn't easy to find out ... you're correct, OnOk and  OnApply are called both for either OK and APPLY buttons. To find out that OK was pressed I only found one way:

derive your own CPropertySheet class, and add a function like this:

// in .h file
class CMyPropSheet: public CPropertySheet
{
 ...
 afx_msg BOOL OnOkPressed();
};

// in .cpp file
BEGIN_MESSAGE_MAP( CMyPropSheet, CPropertySheet)
....
 ON_COMMAND_EX( IDOK, OnOkPressed )
END_MESSAGE_MAP()

BOOL CMyPropSheet::OnOkPressed()
{
 // do here what you need to do
 return FALSE; // return TRUE here if you don't want the property sheet to be closed (then even OnApply and OnOk won't be called)
}


hope this helps,

ZOPPO
0
 
ScattanAuthor Commented:
I'm greatful that you helping me, but unfortunately this doesn't work either.
That would only work if I had put a button on the dialog-resource that had the id IDOK, but it seems like the propertypage default OK-button has another id or something...

Something else...?

I find it strange that this could be so difficult, it should be something the wizard let me do, don't you think?

Thanks!
0
 
ZoppoCommented:
Hmm.., strange, for me it's working and I don't have any controls in my property pages at all! It even works for IDCANCEL and ID_APPLY_NOW. Are you sure you're didn't miss something. Could you post some code where you use the property sheet?
0
 
RONSLOWCommented:
I have the answer for you.

In your handler, do this

PSHNOTIFY* lppsn = (PSHNOTIFY*)GetCurrentMessage()->lParam;
bool IsApply = pllsn->lparam == 0;

Then use IsApply to change how you process it.

0
 
RONSLOWCommented:
oops .. typo
  PSHNOTIFY* lppsn = (PSHNOTIFY*)GetCurrentMessage()->lParam;
  bool IsApply = lppsn->lparam == 0;
0
 
ScattanAuthor Commented:
Hi!

Zoppo: I dont know why it works for you, but in my application it doesn't even notice the ON_COMMAND_EX( IDOK, ...etc.) handler, it ignores it.
I thank you for your help, but I'm going to give the points to RONSLOW, because his way it works for me.

RONSLOW: Thank you for the answer, now it works. Send in a blank question and you'll get the points.



0
 
RONSLOWCommented:
Thanks.

BTW: Zoppos code should work too .. but please note that the change he suggests needs to be made to the property SHEET and must be a ON_COMMAND_EX (not plain old ON_COMMAND) so that the base class handler also gets called.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now