Solved

CPropertyPage

Posted on 2000-03-22
10
661 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 30

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 30

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 30

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

747 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

12 Experts available now in Live!

Get 1:1 Help Now