CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2001
    Posts
    80

    Question 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!

  2. #2
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: Automaticly quit MFC app after launch

    You should call OnClose();
    Please don't forget to rate users who helped you!

  3. #3
    Join Date
    Nov 2003
    Posts
    2,185

    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.

  4. #4
    Join Date
    Oct 2001
    Posts
    80

    Re: Automaticly quit MFC app after launch

    Quote Originally Posted by philkr
    You should call OnClose();
    Could be a bit more precise?

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  6. #6
    Join Date
    Sep 2004
    Location
    cache software
    Posts
    106

    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
  •  





Click Here to Expand Forum to Full Width

Featured