简体   繁体   中英

MFC dialog application not closing

I'm trying to get my CDialog based application to close. I call CWnd::OnClose() and then the debugger goes into windows system files. In the debugger output window I get these looping lines indefinitely.

The thread 'Win32 Thread' (0x1040) has exited with code 0 (0x0). The thread 'Win32 Thread' (0x2fa4) has exited with code 0 (0x0). The thread 'Win32 Thread' (0x1ca0) has exited with code 0 (0x0). 'LifescanDatabaseApplication.exe': Unloaded 'C:\\Windows\\SysWOW64\\davclnt.dll' 'LifescanDatabaseApplication.exe': Unloaded 'C:\\Windows\\SysWOW64\\davhlpr.dll' 'LifescanDatabaseApplication.exe': Loaded 'C:\\Windows\\SysWOW64\\davclnt.dll', Cannot find or open the PDB file 'LifescanDatabaseApplication.exe': Loaded 'C:\\Windows\\SysWOW64\\davhlpr.dll', Cannot find or open the PDB file

Any ideas what I've broken or how I should track it down? Thanks, James

Edit The function OnClose() for the dialog is shown here;

void CApplicationDlg::OnClose()
{
    UpdateData(TRUE);
    if(AfxMessageBox(_T("Are you sure you want to close? If so, no more updates will be issued"),MB_YESNO)==IDYES)
    {
    Logger * instance = Logger::Instance();
    if(instance!=nullptr)
    {
      instance->writeToLogFile("Application shutdown.");
    }
        CWnd::OnClose();
    }
}

I've traced this through with a debugger through the Cwnd::OnClose() command. Problem is, the code isn't getting back to the part that calls the dialog box to run EndDialog. I think I've altered something elsewhere in the dialog box code that is stopping this working.

Edit 2: Replacing CWnd::OnClose() with this->EndDialog(0) appears to fix the problem, but this is worrying.

You should check out CWnd::OnClose in the documentation at http://msdn.microsoft.com/en-us/library/866bc849(v=vs.80).aspx . You will see that it is a function that's called in response to an event occuring: the window RECEIVING a WM_CLOSE message, indicating that the window should close. Simply calling it won't close the window.

You should call EndDialog using the appropriate return code http://msdn.microsoft.com/en-us/library/wddd3ztw%28v=vs.80%29.aspx .

The acutal problem was some confusion in the id's on the buttons which meant that a handler was being called that caused a method to run that took a very long time to complete.

Fixed that and everything worked. Thanks for your help though

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM