这样的程序会不会出现内存泄漏??
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




