Solved

Detect Exit in Dialog

Posted on 2006-06-09
4
571 Views
Last Modified: 2012-06-21
Hi, i made a MFC Dialog.....how do i know if user exit with pressing F4 so that i can perform something before the dialog exit?
Thanks in advance
0
Comment
Question by:iphone
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 16875786
Do you mean Alt+F4? Handle WM_CLOSE message:

void CtMyDlg::OnClose()
{
    // Put your code here.
    // Call CDialog::OnClose to close dialog.
    // return without calling CDialog::OnClose to prevent closing dialog.

    CDialog::OnClose();
}

OnClose function is called when user presses Alt+F4, clicks Close button in the title bar, or selects Close from system menu.
0
 

Author Comment

by:iphone
ID: 16875828
I have put in the code, i tried remove the line CDialog::OnClose(); yes it wont close when pressing alt+f4 meaning it really call the onclose function but then when i put in CDialog::OnClose() as my dialog is CMagazineCleanUpDlg so it looks like CMagazineCleanUpDlg::OnClose() ofcause, but it wont exit and the whole dialog hang, i will have to press ctrl+alt+del and terminate the process.why?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16875847
>> so it looks like CMagazineCleanUpDlg::OnClose() ofcause.

This creates endless recursion. It should be CDialog::OnClose - call to base class function.
0
 

Author Comment

by:iphone
ID: 16875877

oh sorry my mistake...problem solve, thanks alot
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

828 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