视图切换,显示Access violation

ashleycoder 2012-11-09 11:26:06

void CMainFrame::SwitchViews(UINT nID)
{
CView *m_pActiveView=GetActiveView();



CView *pNewView;

switch(nID)
{
case IDD_SYSTEM:
pNewView=(CView*) new CSystem;
break;

case IDD_TEST:
pNewView=(CView*) new CTest;
break;

case IDD_CALIBRATION:
pNewView=(CView*) new CCalibration;
break;

case IDD_QUALITYCONTROL:
pNewView=(CView*) new CQualityControl;
break;
}


CCreateContext newContext;
newContext.m_pNewViewClass = NULL;
newContext.m_pNewDocTemplate = NULL;
newContext.m_pLastView = NULL;
newContext.m_pCurrentFrame = NULL;
newContext.m_pCurrentDoc = GetActiveDocument();


pNewView->Create(NULL,NULL,(AFX_WS_DEFAULT_VIEW & ~WS_VISIBLE),CFrameWnd::rectDefault,this,nID,&newContext);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
pNewView->ShowWindow(SW_SHOW);

SetWindowLong(pNewView->m_hWnd, GWL_ID,AFX_IDW_PANE_FIRST);
RecalcLayout();

m_pActiveView->DestroyWindow();
}

调试create这句,显示Access violation
hwnd显示0xccccccc
怎么改呢?
谢谢
...全文
66 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ashleycoder 2012-11-09
  • 打赏
  • 举报
回复
我不小心把IDD写成IDM了!
Eleven 2012-11-09
  • 打赏
  • 举报
回复
CView  *pNewView = new CNewView; 
	CFrameWnd* pFrame = new CFrameWnd;
       
	CCreateContext newContext;  
	newContext.m_pNewViewClass = NULL; 
    newContext.m_pNewDocTemplate = NULL;  
	newContext.m_pLastView = pNewView;  
	newContext.m_pCurrentFrame = pFrame;   
	newContext.m_pCurrentDoc =NULL;  
	pFrame->Create(NULL, _T("My Windows"), WS_OVERLAPPEDWINDOW, CFrameWnd::rectDefault, NULL, NULL, 0, &newContext);
	pNewView->Create(NULL,NULL, WS_CHILD | WS_VISIBLE,CFrameWnd::rectDefault,pFrame,AFX_IDW_PANE_FIRST,&newContext);   
	pFrame->ShowWindow(SW_SHOW);
	pNewView->OnInitialUpdate();
一般都这么写的

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧