Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   How to Close/Kill Parent from MFC DLL (http://www.go4expert.com/forums/close-kill-parent-mfc-dll-t7331/)

jensjoseph 16Nov2007 18:11

How to Close/Kill Parent from MFC DLL
 
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.

shabbir 16Nov2007 19:01

Re: How to Close/Kill Parent from MFC DLL
 
Try sending the WM_CLOSE message

jensjoseph 16Nov2007 19:30

Re: How to Close/Kill Parent from MFC DLL
 
Are you saying
PostMessage(AfxGetMainWnd()->m_hWnd, WM_CLOSE, SC_CLOSE, NULL);

jensjoseph 16Nov2007 19:30

Re: How to Close/Kill Parent from MFC DLL
 
Are you saying
PostMessage(AfxGetMainWnd()->m_hWnd, WM_CLOSE, NULL, NULL);

jensjoseph 16Nov2007 19:35

Re: How to Close/Kill Parent from MFC DLL
 
I tried WM_CLOSE. But it still crashes.

shabbir 16Nov2007 22:45

Re: How to Close/Kill Parent from MFC DLL
 
Even Alt + F4 crashes so I think there is some problem in the cleanup of your code.


All times are GMT +5.5. The time now is 09:43.