Application Close

Hi all
I am using MFC dialog based application wizard for GUI of my project.
i want to know which function is called when i close the Main Dialog Box?
[158 byte] By [MarcReing] at [2007-11-19 7:09:56]
# 1 Re: Application Close
well, probably the OnOK if you press enter, and the OnCancel if you press escape.

You can also catch the OnClose event.
Tischnoetentoet at 2007-11-11 0:28:22 >
# 2 Re: Application Close
If you use the system menu or system bar to close the dialog a WM_SYSCOMMAND with SC_CLOSE is sent, which is translated into a WM_CLOSE.
cilu at 2007-11-11 0:29:26 >
# 3 Re: Application Close
Thanks for help
But i want to know if i am closing the Dialog box by using the X symbol from the Top right corner then which function will be called
MarcReing at 2007-11-11 0:30:26 >
# 4 Re: Application Close
I told you WM_CLOSE is sent. That means OnClose() gets called by the framework.
cilu at 2007-11-11 0:31:32 >
# 5 Re: Application Close
Hi Cilu
I have tried to search for WM_CLOSE and OnClose in my project
But it doesnt contain any
MarcReing at 2007-11-11 0:32:31 >
# 6 Re: Application Close
You have to handle the WM_CLOSE message, which means:
1) you enter ON_WM_CLOSE() in the message map

BEGIN_MESSAGE_MAP(CYourDlg, CDialog)
//{{AFX_MSG_MAP(...)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
...
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

2)you enter in your dialogs .h file:

afx_msg void OnClose();

3) in your .cpp you write the body of the function:

void CYourDlg::OnClose()
{
//enter other code here
CDialog::OnClose();
}

In other words you override the CDialog::OnClose() function.

Now, if you press the X, the OnCancel() member function is called, you should override that.
szz at 2007-11-11 0:33:32 >