?
Solved

CPropertyPage

Posted on 2000-03-22
10
Medium Priority
?
671 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

Technology Partners: 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!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…
Suggested Courses

765 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