+ -
当前位置:首页 → 问答吧 → CFormview 关闭

CFormview 关闭

时间:2011-12-17

来源:互联网

问题:
点击菜单 弹出新的视图:
void CMainFrame::OnClientinfo()
{
theApp.CreateView(VIEW_CLIENT,NULL); //theApp即CGkencliApp
}

void CGkencliApp::CreateView (int nViewType, LPVOID pData)
{
if (nViewType != VIEW_MAIN && nViewType != VIEW_EXPORT && nViewType != VIEW_CLIENT && pData == NULL)
return;

CGkencliView* pView = FindView(nViewType, pData);
if (pView)
{
ActiveView(pView->GetParent());
return;
}

pView = FindView (VIEW_MAIN, NULL);
double zoom = 1000;
if (pView)
zoom = pView->GetZoom ();

POSITION pos=GetFirstDocTemplatePosition();
CDocTemplate* temp;
if(pos)
temp=GetNextDocTemplate(pos);

CDocument* pDocument = temp->CreateNewDocument();
if (pDocument == NULL)
{
TRACE0("CDocTemplate::CreateNewDocument returned NULL.\n");
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
return ;
}
ASSERT_VALID(pDocument);
CGkencliDoc* pDoc=(CGkencliDoc*)pDocument;

pDoc->SetParam(nViewType, pData, zoom);

BOOL bAutoDelete = pDocument->m_bAutoDelete;
pDocument->m_bAutoDelete = FALSE; // don't destroy if something goes wrong
CFrameWnd* pFrame = temp->CreateNewFrame(pDocument, NULL);
pDocument->m_bAutoDelete = bAutoDelete;
if (pFrame == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
delete pDocument; // explicit delete on error
return;
}
ASSERT_VALID(pFrame);

  pFrame->ModifyStyle(WS_CAPTION | WS_BORDER, 0, 0);

//window title and position
pDocument->SetTitle(pDoc->m_strTitle);
if(nViewType == VIEW_MAIN)
pFrame->ModifyStyle(WS_SIZEBOX, 0, 0);

if (!pDocument->OnNewDocument())
{
// user has be alerted to what failed in OnNewDocument
TRACE0("CDocument::OnNewDocument returned FALSE.\n");
pFrame->DestroyWindow();
return ;
}
temp->InitialUpdateFrame(pFrame, pDocument);
LayoutWnd();
}

然后在:
void CGkencliView::OnInitialUpdate()
{
CEditMap::OnInitialUpdate();
   
  CRect rect;
this->GetActiveWindow()->GetWindowRect(rect);  

  m_ClientControl.Create(NULL,NULL,WS_CHILD|WS_VISIBLE,rect,this,0,NULL);//创建视图对象m_ClientControl
  m_ClientControl.ShowWindow(SW_SHOWNORMAL);
}


为什么退出系统时 出现以后错误::

Windows 已在 gkencli.exe 中触发一个断点。

其原因可能是堆被损坏,这说明 gkencli.exe 中或它所加载的任何 DLL 中有 Bug。

原因也可能是用户在 gkencli.exe 具有焦点时按下了 F12。

输出窗口可能提供了更多诊断信息。


如果不打开这个视图窗口则不会报错,第一次接触CformView 希望各位大侠指教!!

作者: angellove156   发布时间: 2011-12-17

....看到MFC 我就没勇气看下去

作者: zhifeiya   发布时间: 2011-12-17