Realizing "confirm cancel" functionality with property sheets

Hi.

I have a property sheet in my application and need it to show a
confirmation message when user clicks 'Cancel' button, and there are
changes made on some property pages, something like "Do you want to
discard all changes?". The property sheet class itself doesn't have
'OnQueryCancel' method, nor it has 'OnCancel' handler - everything is
in CPropertyPage. If it had, I'd somehow check if any pages were
changed. But now I can't find an elegant method to implement this.
Have you any ideas?

Thanks,
Martin

0
martin-g (64)
9/24/2007 11:53:48 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
621 Views

Similar Articles

[PageSpeed] 13

Also I tried to override 'OnQueryCancel' in every page class of the
property sheet, but only the first page's 'OnQueryCancel' is called...

0
martin-g (64)
9/24/2007 12:21:08 PM
Hi Martin,

Try this,

Put in a handler message for cancel:

BEGIN_MESSAGE_MAP(CMySheet, CPropertySheet)
 ON_COMMAND(IDCANCEL, OnCancel)
END_MESSAGE_MAP()

Then do the handler:

void CMySheet::OnCancel()
{
     if(AfxMessageBox("Do you want to cancel?",MB_YESNO) == IDYES) {
          //Any extra code you need
          EndModalLoop( IDCANCEL );
     }
}

Don't forget this in your .h file:

 virtual void OnCancel();

You could do the same thing with IDOK if you wanted to check that too.

You can also use this to have one page communicate with the others (I.E., a 
value changes or needs to be checked)

http://msdn2.microsoft.com/en-us/library/ykkkze85(VS.80).aspx

HTH,

Tom

"Martin" <martin-g@mail.ru> wrote in message 
news:1190634828.579340.24370@r29g2000hsg.googlegroups.com...
> Hi.
>
> I have a property sheet in my application and need it to show a
> confirmation message when user clicks 'Cancel' button, and there are
> changes made on some property pages, something like "Do you want to
> discard all changes?". The property sheet class itself doesn't have
> 'OnQueryCancel' method, nor it has 'OnCancel' handler - everything is
> in CPropertyPage. If it had, I'd somehow check if any pages were
> changed. But now I can't find an elegant method to implement this.
> Have you any ideas?
>
> Thanks,
> Martin
> 

0
tom.nospam (3240)
9/24/2007 2:18:08 PM
On Sep 24, 7:18 pm, "Tom Serface" <tom.nos...@camaswood.com> wrote:
> Hi Martin,
>
> Try this,
>
> Put in a handler message for cancel:
>
> BEGIN_MESSAGE_MAP(CMySheet, CPropertySheet)
>  ON_COMMAND(IDCANCEL, OnCancel)
> END_MESSAGE_MAP()
>
> Then do the handler:
>
> void CMySheet::OnCancel()
> {
>      if(AfxMessageBox("Do you want to cancel?",MB_YESNO) == IDYES) {
>           //Any extra code you need
>           EndModalLoop( IDCANCEL );
>      }
>
> }
>
> Don't forget this in your .h file:
>
>  virtual void OnCancel();
>
> You could do the same thing with IDOK if you wanted to check that too.
>
> You can also use this to have one page communicate with the others (I.E., a
> value changes or needs to be checked)
>
> http://msdn2.microsoft.com/en-us/library/ykkkze85(VS.80).aspx
>
> HTH,
>
> Tom

Thanks Tom. Though I was oblidged to go another way. Using 'OnCancel'
this way doesn't cover cases when user simply closes the property
sheet using cross or sysmenu. I decided to override 'OnQueryCancel'
for every page, and it seems to work normally, though the method can't
be called elegant.

0
martin-g (64)
9/27/2007 8:12:05 AM
That's the better way to do it (OnQueryCancel()), but I thought you didn't 
want to do that so I was presenting another way.  You could, of course, 
catch the WM_CLOSE message as well, but I'm glad you got it working.  The 
way you're going gives you a lot of flexibility.

Tom

"Martin" <martin-g@mail.ru> wrote in message 
news:1190880725.445117.114460@r29g2000hsg.googlegroups.com...
> On Sep 24, 7:18 pm, "Tom Serface" <tom.nos...@camaswood.com> wrote:
>> Hi Martin,
>>
>> Try this,
>>
>> Put in a handler message for cancel:
>>
>> BEGIN_MESSAGE_MAP(CMySheet, CPropertySheet)
>>  ON_COMMAND(IDCANCEL, OnCancel)
>> END_MESSAGE_MAP()
>>
>> Then do the handler:
>>
>> void CMySheet::OnCancel()
>> {
>>      if(AfxMessageBox("Do you want to cancel?",MB_YESNO) == IDYES) {
>>           //Any extra code you need
>>           EndModalLoop( IDCANCEL );
>>      }
>>
>> }
>>
>> Don't forget this in your .h file:
>>
>>  virtual void OnCancel();
>>
>> You could do the same thing with IDOK if you wanted to check that too.
>>
>> You can also use this to have one page communicate with the others (I.E., 
>> a
>> value changes or needs to be checked)
>>
>> http://msdn2.microsoft.com/en-us/library/ykkkze85(VS.80).aspx
>>
>> HTH,
>>
>> Tom
>
> Thanks Tom. Though I was oblidged to go another way. Using 'OnCancel'
> this way doesn't cover cases when user simply closes the property
> sheet using cross or sysmenu. I decided to override 'OnQueryCancel'
> for every page, and it seems to work normally, though the method can't
> be called elegant.
> 

0
tom.nospam (3240)
9/27/2007 2:58:17 PM
Reply:

Similar Artilces:

Realizing "confirm cancel" functionality with property sheets
Hi. I have a property sheet in my application and need it to show a confirmation message when user clicks 'Cancel' button, and there are changes made on some property pages, something like "Do you want to discard all changes?". The property sheet class itself doesn't have 'OnQueryCancel' method, nor it has 'OnCancel' handler - everything is in CPropertyPage. If it had, I'd somehow check if any pages were changed. But now I can't find an elegant method to implement this. Have you any ideas? Thanks, Martin Also I tried to override 'OnQueryCan...