Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

dialog app wont close

Posted on 2004-04-23
4
374 Views
Last Modified: 2013-11-20
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
Comment
Question by:lwinkenb
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
wayside earned 50 total points
ID: 10903032
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
 
LVL 1

Expert Comment

by:kevinnguyen
ID: 10903064
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
 
LVL 7

Expert Comment

by:vijay_visana
ID: 10906412
///////////////////////////////////////////////////
//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
 
LVL 7

Expert Comment

by:vijay_visana
ID: 10906517
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 137
countEvens challenge 2 111
wordcount challenge 11 130
Increment column based of a FK 8 31
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question