应用程序在关闭时崩溃:可能是由于多个子对话框 [英] Application crashes when closed: possibly due to multiple child dialogs

查看:103
本文介绍了应用程序在关闭时崩溃:可能是由于多个子对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MFC和C ++的新手.

一些背景信息:
我正在创建一个工具来显示7个对话框中的图形.我将父对话框创建为模式类型,并在其OnInitDialog()中创建6个不同的无模对话框(一个父,多个子).以下是我用来创建1个无模式对话框的代码:

I am a newbie to MFC and C++.

Some background info:
I am creating a tool to display graphs across 7 dialogs. I am creating the parent dialog as a modal type and in its OnInitDialog(), i am creating 6 different modeless dialogs (one parent, multiple child). Following is the code that i am using to create 1 modeless dialog:

nbiq_dlg2 = new nbiq_dialog2(this);
if (TRUE == nbiq_dlg2->Create())
{
    nbiq_dlg2->ShowWindow(true);
}



我正在使用MSDN的示例项目中给出的类似方法来创建和销毁无模式对话框:
http://msdn.microsoft.com/en-us/library/zhk0y9cw% 28VS.80%29.aspx [ ^ ]

我的应用程序不希望用户输入任何内容,因此没有按钮.我确保关闭主对话框时,如果所有子对话框都没有,则销毁所有子对话框.

问题:
但是,当我运行该程序时,一切正常,直到我开始关闭对话框. 5次中有4次,应用程序崩溃,当我按调试"时,出现以下错误:

在"0x00000000"处的指令在"0x00000000"处被引用.无法读取内存.


在调试模式下,关闭任何对话框"test.exe中的第一次机会异常:0xc0000005:访问冲突"和



I am using the similar method given in a sample project by MSDN to create and destroy the modeless dialogs:
http://msdn.microsoft.com/en-us/library/zhk0y9cw%28VS.80%29.aspx[^]

My application does not expect any input from the user and thus has no buttons. I am making sure that when the main dialog is closed, all the child dialogs are destroyed if they are already not.

Problem:
However when i run this program, everything is fine until i start closing the dialogs. 4 out of 5 times, the application crashes and when i press "Debug", it gives the following error:

The instruction at "0x00000000" referenced at "0x00000000". The memory could not be read.


During debug mode, i get this error when i close any of the dialogs "first chance exception in test.exe: 0xc0000005: access violation" and

this    CXX0017: Error: symbol "this" not found



同样,这并非每次都会发生.

我已经调试了这个问题一个多星期,但仍然无法找出问题所在.任何见解/想法将是最有帮助的.

谢谢,
Hari



Again, this does not happen every time.

I have been debugging this issue for over a week and i am still not able to figure out the fault. Any insights/ideas would be most helpful.

Thanks,
Hari

推荐答案

尝试按以下顺序打开一个孩子:
Try this sequence to open a child :
{
  if (!m_pcChild) {
    m_pcChild = new ..;
  }
  if (!m_pcChild->GetSafeHwnd()) {
    m_pcChild->Create(..);
  }
  if (m_pcChild->GetSafeHwnd()) {
    m_pcChild->ShowWindow(SW_SHOW);
  }
}

...隐藏它:

...to hide it:

{
  if (m_pcChild->GetSafeHwnd()) {
    m_pcChild->ShowWindow(SW_HIDE);
  }
}

...并销毁它:):

...and to destroy it :) :

{
  if (m_pcChild->GetSafeHwnd()) {
    m_pcChild->DestroyWindow();
  }
  if (m_pcChild) {
    delete m_pcChild;
  }
  m_pcChild = NULL; // the same line should be placed
                    // in the constructor of your parent 
}


R u在静态函数中使用它吗?
R u using this inside a static function???


不.我没有使用静态函数.既然我是新手,这有什么不同吗?

哈里
No. I am not using static functions. Since i am new to this, does it make a difference?

Hari


这篇关于应用程序在关闭时崩溃:可能是由于多个子对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆