1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to Close/Kill Parent from MFC DLL

Discussion in 'MFC' started by jensjoseph, Nov 16, 2007.

  1. jensjoseph

    jensjoseph New Member

    Joined:
    Nov 16, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi

    I have an MFC DLL thats called by another application. When I hit Alt-F4 on the parent window, it closes itself and my MFC DLL application as well.

    I have been trying to implement the same from my MFC DLL application as well. i.e. When I hit Alt+F4 from my MFC DLL app, it should close itself and the calling application as well.

    I've tried the following in the OnClose message handler of the MFC DLL application:

    1. DestroyWindow(GetParent()->m_hWnd);
    2. DestroyWindow(AfxGetMainWnd()->GetParent()->m_hWnd);
    3. DestroyWindow(AfxGetMainWnd()->m_hWnd);
    4. PostMessage(AfxGetMainWnd()->m_hWnd, WM_SYSCOMMAND, SC_CLOSE, NULL);

    However, none of them seems to be working: When I hit Alt+F4, the MFC DLL application closes followed by a crash message from Windows.

    A quick reply would help immensely.

    Thanks.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Try sending the WM_CLOSE message
     
  3. jensjoseph

    jensjoseph New Member

    Joined:
    Nov 16, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Are you saying
    PostMessage(AfxGetMainWnd()->m_hWnd, WM_CLOSE, SC_CLOSE, NULL);
     
  4. jensjoseph

    jensjoseph New Member

    Joined:
    Nov 16, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Are you saying
    PostMessage(AfxGetMainWnd()->m_hWnd, WM_CLOSE, NULL, NULL);
     
  5. jensjoseph

    jensjoseph New Member

    Joined:
    Nov 16, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I tried WM_CLOSE. But it still crashes.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Even Alt + F4 crashes so I think there is some problem in the cleanup of your code.
     

Share This Page