Solved

CPropertyPage

Posted on 2000-03-22
10
666 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

831 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