简体   繁体   English

MFC对话框应用程序未关闭

[英]MFC dialog application not closing

I'm trying to get my CDialog based application to close. 我正在尝试关闭基于CDialog的应用程序。 I call CWnd::OnClose() and then the debugger goes into windows system files. 我调用CWnd :: OnClose(),然后调试器进入Windows系统文件。 In the debugger output window I get these looping lines indefinitely. 在调试器输出窗口中,我无限期地获得这些循环线。

The thread 'Win32 Thread' (0x1040) has exited with code 0 (0x0). 线程'Win32 Thread'(0x1040)已退出,代码为0(0x0)。 The thread 'Win32 Thread' (0x2fa4) has exited with code 0 (0x0). 线程'Win32 Thread'(0x2fa4)已退出代码0(0x0)。 The thread 'Win32 Thread' (0x1ca0) has exited with code 0 (0x0). 线程'Win32 Thread'(0x1ca0)已退出,代码为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 'LifescanDatabaseApplication.exe':卸载'C:\\ Windows \\ SysWOW64 \\ davclnt.dll''LifescanDatabaseApplication.exe':卸载'C:\\ Windows \\ SysWOW64 \\ davhlpr.dll''LifescanDatabaseApplication.exe':已加载'C:\\ Windows \\ SysWOW64 \\ davclnt.dll',找不到或打开PDB文件'LifescanDatabaseApplication.exe':加载'C:\\ Windows \\ SysWOW64 \\ davhlpr.dll',无法找到或打开PDB文件

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; 编辑此处显示对话框的函数OnClose();

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. 我通过Cwnd :: OnClose()命令通过调试器跟踪了这一点。 Problem is, the code isn't getting back to the part that calls the dialog box to run EndDialog. 问题是,代码没有回到调用对话框来运行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. 编辑2:用this-> EndDialog(0)替换CWnd :: OnClose()似乎可以解决问题,但这很令人担忧。

You should check out CWnd::OnClose in the documentation at http://msdn.microsoft.com/en-us/library/866bc849(v=vs.80).aspx . 您应该在http://msdn.microsoft.com/en-us/library/866bc849(v=vs.80).aspx的文档中查看CWnd :: OnClose。 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. 您将看到它是响应事件发生而调用的函数:窗口RECEIVING WM_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 . 您应该使用适当的返回码http://msdn.microsoft.com/en-us/library/wddd3ztw%28v=vs.80%29.aspx调用EndDialog。

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. 真正的问题是按钮上的id有些混乱,这意味着正在调用一个处理程序,导致一个方法运行需要很长时间才能完成。

Fixed that and everything worked. 修正了这一切,一切正常。 Thanks for your help though 谢谢你的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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