CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

这样的程序会不会出现内存泄漏??

楼主pcvc(用户中文昵称)2003-11-02 00:09:59 在 VC/MFC / 基础类 提问

void   CMyDlg::OnTimer(UINT   nIDEvent)  
  {  
  //   TODO:   Add   your   message   handler   code   here   and/or   call   default  
   
  switch   (nIDEvent)  
  {  
  case   1:  
  pdlg   =   new   CNewDlg;       //CNewDlg   *CMyDlg::pdlg  
  KillTimer(1);  
  pdlg->Create(IDD_DIALOG1);  
  pdlg->ShowWindow(SW_SHOW);  
  }  
   
  CDialog::OnTimer(nIDEvent);  
  }  
   
  注意:还有以下函数!!!!  
   
  void   CNewDlg::PostNcDestroy()    
  {  
  //   TODO:   Add   your   specialized   code   here   and/or   call   the   base   class  
   
  delete   this;  
   
  CDialog::PostNcDestroy();  
  } 问题点数:0、回复次数:7Top

1 楼pcvc(用户中文昵称)回复于 2003-11-02 00:21:04 得分 0

如果   OnTimer   函数是下面内容又是如何呢?  
   
  //计数器1和2分别为1秒和5秒。  
   
  void   CMyDlg::OnTimer(UINT   nIDEvent)  
  {  
  //   TODO:   Add   your   message   handler   code   here   and/or   call   default  
   
  switch   (nIDEvent)  
  {  
  case   1:  
  {  
  CNewDlg   *pdlg1   =   new   CNewDlg;  
  KillTimer(1);  
  pdlg1->Create(IDD_DIALOG1);  
  pdlg1->ShowWindow(SW_SHOW);  
  }  
  break;  
  case   2:  
  CNewDlg   *pdlg2   =   new   CNewDlg;  
  KillTimer(2);  
  pdlg2->Create(IDD_DIALOG1);  
  pdlg2->ShowWindow(SW_SHOW);  
  break;  
  }  
   
  CDialog::OnTimer(nIDEvent);  
  }  
   
  还有,为什么我去掉   case   1:   后的一对   {}   ,程序为什么就会出错呢???  
   
  谢谢!!!Top

2 楼pcvc(用户中文昵称)回复于 2003-11-02 00:28:17 得分 0

MSDN:  
   
  Called   by   the   default   OnNcDestroy   member   function   after   the   window   has   been   destroyed.   Derived   classes   can   use   this   function   for   custom   cleanup   such   as   the   deletion   of   the   this   pointer.  
   
  我想应该不会吧!!Top

3 楼pcvc(用户中文昵称)回复于 2003-11-02 00:59:21 得分 0

??还没有关注??  
   
  -----------------------------------------------------  
   
  我装了BoundsChecker   6.01  
   
  选择   Build   >>   Rebuild   All   没有任何错误。  
  选择   BoundsChecker   >>   Rebuild   All   with   BoundsChecker   却出现以下错误:  
   
  Deleting   intermediate   files   and   output   files   for   project   '55555   -   Win32   Debug'.  
  --------------------Configuration:   55555   -   Win32   Debug--------------------  
  Compiling   resources...  
  Compiling...  
  StdAfx.cpp  
  Instrumentation   of   C:\Documents   and   Settings\Administrator\桌面\55555\StdAfx.cpp   starting...  
  error:   skipping   instrumentation;   Unsupported   Compiler   Version  
  Instrumentation   of   C:\Documents   and   Settings\Administrator\桌面\55555\StdAfx.cpp   stopping  
  Compiling...  
  55555.cpp  
  55555Dlg.cpp  
  NewDlg.cpp  
  Generating   Code...  
  Instrumentation   of   C:\Documents   and   Settings\Administrator\桌面\55555\NewDlg.cpp   starting...  
  error:   skipping   instrumentation;   Unsupported   Compiler   Version  
  Instrumentation   of   C:\Documents   and   Settings\Administrator\桌面\55555\NewDlg.cpp   stopping  
  Instrumentation   of   C:\Documents   and   Settings\Administrator\桌面\55555\55555Dlg.cpp   starting...  
  error:   skipping   instrumentation;   Unsupported   Compiler   Version  
  Instrumentation   of   C:\Documents   and   Settings\Administrator\桌面\55555\55555Dlg.cpp   stopping  
  Instrumentation   of   C:\Documents   and   Settings\Administrator\桌面\55555\55555.cpp   starting...  
  error:   skipping   instrumentation;   Unsupported   Compiler   Version  
  Instrumentation   of   C:\Documents   and   Settings\Administrator\桌面\55555\55555.cpp   stopping  
  Linking...  
   
  55555.exe   -   4   error(s),   0   warning(s)  
   
   
  这是为什么?Top

4 楼thunder76(thunder)回复于 2003-11-02 09:58:51 得分 0

void   CMyDlg::OnTimer(UINT   nIDEvent)  
  {  
  //   TODO:   Add   your   message   handler   code   here   and/or   call   default  
   
  switch   (nIDEvent)  
  {  
  case   1:  
  {  
  CNewDlg   *pdlg1   =   new   CNewDlg;  
  KillTimer(1);  
  pdlg1->Create(IDD_DIALOG1);  
  pdlg1->ShowWindow(SW_SHOW);  
  }                   //指针pdlg1只能到此处,你new的dialog如何析构?  
  break;  
  case   2:  
  CNewDlg   *pdlg2   =   new   CNewDlg;  
  KillTimer(2);  
  pdlg2->Create(IDD_DIALOG1);  
  pdlg2->ShowWindow(SW_SHOW);  
  break;  
  }  
   
  CDialog::OnTimer(nIDEvent);  
  }  
   
  还有,两个对话框使用统一个资源,会不会出问题?  
  第一个程序,总觉得不合适,为什么不让CMyDlg清理new出来的东西?谁创建,谁清除,这样更合理一些。  
  Top

5 楼pcvc(用户中文昵称)回复于 2003-11-02 11:24:24 得分 0

程序运行没什么问题!!!!Top

6 楼pcvc(用户中文昵称)回复于 2003-11-02 16:03:53 得分 0

为什么我的问题老是没人关注呢??  
   
  WHY!!!!!!!Top

7 楼pcvc(用户中文昵称)回复于 2003-11-03 09:12:42 得分 0

最后一下了。Top

相关问题

  • 这样字符串指针会不会出现内存泄漏??
  • 帮帮忙,我的程序出现内存泄漏!!
  • 如果在一个程序中使用了堆内存,但并不回收,会不会造成内存泄漏
  • 在程序中直接使用字符串常量如"abc"到底会不会引起内存泄漏??
  • CArray会不会造成内存泄漏?
  • directdraw程序内存泄漏,咋回事?
  • 我的程序使用 new 的时候出现了内存泄漏,请高手帮忙看一下。谢谢!
  • 请问_bstr_t会不会引起内存泄漏?
  • unix下的opendir()会不会内存泄漏
  • 这段代码会不会内存泄漏,如果是java呢

关键词

  • win32
  • 桌面
  • cpp
  • cnewdlg
  • pdlg
  • nidevent
  • ontimer
  • cmydlg
  • defaultswitch
  • killtimer

得分解答快速导航

  • 帖主:pcvc

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo