Solved

Detect Exit in Dialog

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

758 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

22 Experts available now in Live!

Get 1:1 Help Now