• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

dialog app wont close

I changed the InitInstance() of my dialog app to:

      CMyDlg* dlg;
      dlg = new CMyDlg;
      m_pMainWnd = dlg;
      dlg->Create(IDD_MY_DIALOG);
      dlg->ShowWindow(SW_SHOW);

      // Return TRUE to start the application message pump
      return TRUE;

The problem is that when I close the dialog, it disappears, but I still the process running in the task manager.  What else do I need to do to ensure that my application closes all the way?
0
lwinkenb
Asked:
lwinkenb
  • 2
1 Solution
 
waysideCommented:
Is your dialog modeless? If not, just do this:

     CMyDlg dlg;
     m_pMainWnd = &dlg;
     dlg.DoModal();
     return FALSE;


The other thing you could do is add an event handler for whatever button closes the dialog, and call PostQuitMessage() in it. This posts a WM_QUIT message and will cause the app to exit the message loop and terminate.
0
 
kevinnguyenCommented:
It seems to me that when you close the main app, the modeless dialog process is still running. If that is the case, then do this:

1) Declare CMyDlg* dlg inside your main app (public or protected doesn't really matter).

2) Inside InitInstance(), call the following

a) dlg->Create(IDD_MY_DIALOG);
b) dlg->ShowWindow(SW_SHOW);

3) Add to main app a WM_DESTROY handler. Inside this handler, call dlg->DestroyWindow(). This will kill the running process for the modeless dialog.

kevinnguyen
0
 
vijay_visanaCommented:
///////////////////////////////////////////////////
//your yourapp.cpp

BOOL CDlgTestApp::InitInstance()
{

               m_pDlg = new CDlgTestDlg ;

      m_pMainWnd = m_pDlg  ;
      m_pDlg->Create(IDD_DLGTEST_DIALOG);
      m_pDlg->ShowWindow (SW_SHOW);
      return TRUE;
}

int CDlgTestApp::ExitInstance()
{
      if(m_pDlg )
                      delete m_pDlg ;
}

////////////////////////////////////////////////
//Yourappdlg.cpp

void CDlgTestDlg::OnClose()
{
      PostQuitMessage(0);
      CDialog::OnClose();
}

0
 
vijay_visanaCommented:
The solution given by wayside is bit sidetracking as in your question it seems that you are creating modeless dialog and hence the problem(in case of modal dialog there is no problem as such)
what I have given you is answer of what you have asked.

I am not objecting your acceptence of answer but then you (everyone) should be very clear in your(their) question so experts are not diverted to wrong direction and waste their time for nothing.

Vijay
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now