• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 916
  • Last Modified:

Handling ID_APP_EXIT message.

I'm trying to write a routine which will prompt the user to save
an unsaved document (I'm not using the serialize functions).  

I'd like the routine to simply check a boolean (which is in the document
class) and then call my OnFileSave routine (in the document class)
if needed.

I'm trying to have the ID_APP_EXIT message handled in the document
class.  The problem is that after this message has been handled, I
would still like to exit the application.  How do I do this?  I can't
seem to be able to call the CWinApp:ExitInstance() function from
the document class.

The other approach would be to handle the ID_APP_EXIT message
in the application class, but I would somehow need to get it
to call my save function in the document class.

What's my best course of action?
0
mosaicer
Asked:
mosaicer
1 Solution
 
CJ_SCommented:
PostQuitMessage(0);

or does that not work in MFC? Stupid MFC =(....laughs, try it mate, it works in win32, so maybe you are lucky.
0
 
chensuCommented:
::AfxGetMainWnd()->PostMessage(WM_CLOSE);
0
 
mosaicerAuthor Commented:
Thanks!

0
 
yaoliweiCommented:
CWnd* pwndMain = (CWnd*)AfxGetMainWnd();
pwndMain->SendMessage (WM_CLOSE,0,0);


By the way the comment of "CJ S" is not a good method which will cause a memory leak.


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now