Solved

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

Posted on 1997-11-14
4
984 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
child constructor and parent constructor, overriding and overloading 6 77
NotAlone Challenge 20 79
Change to event 1 99
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

930 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

15 Experts available now in Live!

Get 1:1 Help Now