Solved

CPropertyPage

Posted on 2000-03-22
10
665 Views
Last Modified: 2012-06-27
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
Comment
Question by:Scattan
  • 4
  • 3
  • 3
10 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 2644146
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
 

Author Comment

by:Scattan
ID: 2644326
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
 

Author Comment

by:Scattan
ID: 2644480
(I ment the default-buttons ofcourse, the ones I cannot add myself Apply,OK,Cancel & Help)
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2644685
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
 

Author Comment

by:Scattan
ID: 2645316
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 31

Expert Comment

by:Zoppo
ID: 2645358
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2647458
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2647463
oops .. typo
  PSHNOTIFY* lppsn = (PSHNOTIFY*)GetCurrentMessage()->lParam;
  bool IsApply = lppsn->lparam == 0;
0
 

Author Comment

by:Scattan
ID: 2648121
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
 
LVL 10

Accepted Solution

by:
RONSLOW earned 50 total points
ID: 2648848
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now