-
August 12th, 2005, 02:42 AM
#1
Automaticly quit MFC app after launch
Hi guru's,
I'm a noob when it comes to MFC, so i hope someone can help me here.
I created a MFC app using CFormView. What I want to do, is
1. Start application
2. Do something the user only sees briefly
3. Close tha app without user intervention.
I can do this with:
Code:
void MyView::OnSetFocus(CWnd* pOldWnd)
{
CFormView::OnSetFocus(pOldWnd);
PostQuitMessage ( 0 );
}
but then I get memory leaks. When I leave this code out and close the app manually, I have no memory leaks.
Can someone help me on this? Why do I have memory leaks this way? How can I achieve what I want.
Many thanks in advance!
-
August 12th, 2005, 02:48 AM
#2
Re: Automaticly quit MFC app after launch
You should call OnClose();
Please don't forget to rate users who helped you!
-
August 12th, 2005, 02:49 AM
#3
Re: Automaticly quit MFC app after launch
well, why working with CMainFrame anyway if the user cannot interact?
You have a file called [projectname].cpp. It should contain the function InitInstance().
You can use this function to execute some code and then end:
Code:
BOOL CMyClass::InitInstance();
{
// You code, if you want to show data, use a dialog!
// Stop message loop (and so close application)
return TRUE;
}
You can compare (not really the same, but if you think a little bit "wide", you can compare it) with the main in a normal c++ application.
-
August 12th, 2005, 02:54 AM
#4
Re: Automaticly quit MFC app after launch
Originally Posted by philkr
You should call OnClose();
Could be a bit more precise?
-
August 12th, 2005, 08:01 AM
#5
Re: Automaticly quit MFC app after launch
A dialog app would be better in this case it sounds like. As soon as you close the dialog, the app would end.
-
August 12th, 2005, 08:09 AM
#6
Re: Automaticly quit MFC app after launch
Instead of PostQuitMessage ( 0 ) you should use DestroyWindow() .
The pointer to the window isn't deleted so that's why you're getting a memory leak . Look for DestroyWindow( ) in MSDN !
__________________________________
s.m.a.r.t+s.m.a.r.t = ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|