Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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