为什么?我用delete时老是出错
void CMainFrame::SwitchToForm(int nForm,int nView)
{
CView* pOldActiveView=GetActiveView();
CView* pNewActiveView=(CView*)GetDlgItem(nForm);
if(pNewActiveView==NULL)
{
switch(nForm)
{
case IDD_FCON:
pNewActiveView=(CView*) new CFCON;
break;
}
CCreateContext context;
context.m_pCurrentDoc=pOldActiveView->GetDocument();
pNewActiveView->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,nForm,
&context);
pNewActiveView->OnInitialUpdate();
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
::SetWindowLong(pNewActiveView->m_hWnd,GWL_ID,AFX_IDW_PANE_FIRST);
RecalcLayout();
delete pOldActiveView;//此处老是出错。为什么?
}
}
void CMainFrame::SwitchToForm(int nForm,int nView)
{
CView* pOldActiveView=GetActiveView();
CView* pNewActiveView=(CView*)GetDlgItem(nForm);
if(pNewActiveView==NULL)
{
switch(nForm)
{
case IDD_FCON:
pNewActiveView=(CView*) new CFCON;
break;
}
CCreateContext context;
context.m_pCurrentDoc=pOldActiveView->GetDocument();
pNewActiveView->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,nForm,
&context);
pNewActiveView->OnInitialUpdate();
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
::SetWindowLong(pNewActiveView->m_hWnd,GWL_ID,AFX_IDW_PANE_FIRST);
RecalcLayout();
delete pOldActiveView;//此处老是出错。为什么?
}
}
解决方案 »
- 德安进销存文件版本号1.0.0.4,欢迎大家测试
- 大家好 关于串口通讯的问题。
- 为什么我的OnReceive不会触发?
- CreateEvent中的第四个参数是什么?
- 请问:如何获得word文档的总页数以及当前页码?
- 我的idl怎么不认TRANSACTION_REQUIRED关键字
- 怎样才能将我的从CView继承的类改成从CWnd继承的类??高分求解
- _bstr_t 是怎么用的?新手入门,多多关照
- 菜鸟问题,从java转学VC该怎么做?
- VC中如何存放用CRecordset类读取的NTEXT字段类型?用CSTRING和CDBVariant都报错
- 一个辣手的问题!(跟菜单有关)
- 关于CDialogBar的问题???????????
编译时无错误
运行时出来终止、重试、忽略的错误
提示:
Debug Assertion Failed!
Program:E:\edittest\edittest\debug\edittest.exe
file:cmdtarg.cpp
line: 52
for information on how your program can cause an assertion
failure,see the Visual C++ documentation on assert
(Press Retry to debug the application)
你的办法好象不行
在关闭时出终止、重试、忽略的错误
http://www.codeproject.com/docview/replacingview.asp
pOldActiveView->DestroyWindow();
就可以了!,因为微软希望程序员在对视图,框架通常是采用的创建上通常采用动态创建,一般不由使用者进行new的操作,所以他们是自动释放的,也就是说,如果你也调用delete的话,那么就等于对一个空的指针进行删除操作,当然要出现非法操作了。详细可见OnNcDestroy消息响应函数。
pOldActiveView->DestroyWindow();这个我也试过了,
虽然当时可以运行过去
但是在关闭整个程序时就会出错
why?