Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PostQuitMessage and MFC?

340 views
Skip to first unread message

Mike Boone

unread,
Feb 1, 1997, 3:00:00 AM2/1/97
to

Hi all.

I'm working on an application where I need to trap the File/Exit command before I quit the application. When I do this, however, I get the following debug errors:

OnAppExit()
Warning: destroying CSingleDocTemplate with live document.
Detected memory leaks!
(list of dumped objects)

Here's the code that produces this error:

void CFTForm::OnAppExit() //CFTForm is derived from CFormView
{
if (AskSave()==TRUE)
{
OutputDebugString("OnAppExit()\n");
m_FTApp->ExitCheck();
PostQuitMessage(0);
}
}

Can I use PostQuitMessage with MFC? If not, what should I call to get the application to close from here?

Any info would be appreciated.
Thanks.
Mike.
----------------------------------------------------------------
Mike Boone <Mike-...@msn.com>  http://boonedocks.simplenet.com
  "I've got a Caribbean Soul I can barely control and some
     Texas hidden here in my heart..." - Jimmy Buffett

lo...@cadvision.com

unread,
Feb 2, 1997, 3:00:00 AM2/2/97
to

Hi Mike;
With reguard to your exit app problem

try this code instead

void ExitApp()
{
// same as double clicking on main window close box
ASSERT(AfxGetApp()->m_pMainWnd!=NULL);
AfxGetApp()->m_pMainWnd->SendMessage(WM_CLOSE);
}


I use it all of the time and don't have any problem with it. Here is a sample of one of my calles to it

// other on draw code

if(info.DoModal() !=IDOK ) {
// user has selected cancel
ExitApp();
return;
}

// more on draw code

// end of on draw code
ExitApp();
}

Hope this helps

Joe Love
lo...@cadvision.com
and
lo...@gice.com
www.gice.com/tomas/


Joseph M. O'Leary

unread,
Feb 2, 1997, 3:00:00 AM2/2/97
to

Mike,

You could try calling the CWinApp::CloseAllDocuments() member functions,
but I think a better way
would be to post a WM_CLOSE message to your main window like this>

AfxGetMainWnd()->PostMessage(WM_CLOSE);

HTH

Joe O'

Mike Boone <Mike-...@msn.com> wrote in article
<01bc108b$c832c400$06261fce@bubba>...
Hi all.

----------


Jim Hewitt

unread,
Feb 3, 1997, 3:00:00 AM2/3/97
to

You can use PostQuitMessage(0) in MFC. It posts the WM_QUIT message to your
message loop. The problem is that the document isn't being cleaned up
first. You may want to move your AskSave() function to the CDocument
derived class' CanCloseFrame function. When the CFrameWnd receives a
WM_CLOSE message it calls the CDocument::CanCloseFrame() first, then cleans
up the document and views if the CanCloseFrame returns TRUE, and then calls
PostQuitMessage(0).

Hope this helps.

Troy Ockert & Jim Hewitt

Aditi Corporation

unread,
Feb 3, 1997, 3:00:00 AM2/3/97
to


Hi Mike,


<<<<<
I'm working on an application where I need to trap the File/Exit command
before I quit the application. When I do this, however, I get the following
debug errors:
OnAppExit()
Warning: destroying CSingleDocTemplate with live document.
Detected memory leaks!
(list of dumped objects)
>>>>>

Did you try the ExitProcess function? The syntax for this function is:

::ExitProcess(0);

Hope this helps!
Jagadish
Aditi Corp.

Aditi Corp was formerly known as NetQuest Inc.


Bryan Donaldson

unread,
Feb 3, 1997, 3:00:00 AM2/3/97
to

Use the following in place of the PostQuitMessage. It'll call
CanCloseFrame (and whatever else should happen when the main window is
closed.) PostQuitMessage seems to be thought of as an Error Exit process
by MS types. It doesn't do a lot of the cleanup that the MFC exit process
would do.


CWnd * pWnd = AfxGetMainWnd();
if (pWnd != NULL)
pWnd->PostMessage(WM_CLOSE);

Mike Boone <Mike-...@msn.com> wrote in article
<01bc108b$c832c400$06261fce@bubba>...

Can I use PostQuitMessage with MFC? If not, what should I call to get the
application to close from here?

0 new messages