Solved

Detect Exit in Dialog

Posted on 2006-06-09
4
564 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

778 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