Solved

How to add confirmation message box when a Dialog's CANCEL button is pressed

Posted on 1997-11-14
4
1,015 Views
Last Modified: 2013-11-19
How can I add a confirmation message box when a CANCEL button of a dialog box is pressed ?
Where should I create the confirmation message box. The confirmation message box will have a Yes and No button.
If the No button is selected then I don't want to close the dialog box. If the Yes button is selected then I want to continue closing of the dialog box.
0
Comment
Question by:ehandojo
[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
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 0 total points
ID: 1310004
Override CDialog::OnCancel().

.h

class CMyDlg : public CDialog
{
protected:
...
    virtual void OnCancel();
...
}

.cpp

void CMyDlg::OnCancel()
{
    if (::AfxMessageBox("Are you sure you want to cancel?", MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) == IDYES)
        CDialog::OnCancel();
}

0
 

Author Comment

by:ehandojo
ID: 1310005
Thanks for the answer. Why can't I do the same thing for a CPropertyPage derived class used in CPropertySheet as a wizard ?
I tried to override the OnCancel virtual function on my CPropertyPage derived class and add a confirmation message box, but either Yes and No answer will still close the wizard.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1310006
That is different. CPropertyPage is derived from CDialog, but CPropertyPage is integrated into CPropertySheet and the close operation is done by CPropertySheet. In this case, override CPropertyPage::OnQueryCancel().

CPropertyPage::OnQueryCancel
virtual BOOL OnQueryCancel( );

Return Value

Returns FALSE to prevent the cancel operation or TRUE to allow it.

Remarks

This member function is called by the framework when the user clicks the Cancel button and before the cancel action has taken place.

Override this member function to specify an action the program takes when the user clicks the Cancel button.

The default implementation of OnQueryCancel returns TRUE.


0
 

Author Comment

by:ehandojo
ID: 1310007
thank you for the answer.
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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 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