如题
我运行程序的时候,不能实现根据名字激活
并且程序关闭的时候出现警告:
应用程序发生异常unknown software exception (0x80000003),位置为0x77f813b1。
void CMainFrame::OnActiveView()
{
// TODO: Add your command handler code here
POSITION pos = ((CLApp*)AfxGetApp())->pDocTemplate->GetFirstDocPosition();
while (pos != NULL)
{
CLDoc* pDoc =(CLDoc*)((CLApp*)AfxGetApp())->pDocTemplate->GetNextDoc(pos);
if(pDoc->GetTitle() == "encode")//encode比如我想机会文档名为encode 的窗口
{
POSITION pos1 = pDoc->GetFirstViewPosition();
CView* pView = pDoc->GetNextView(pos1); CString test;
test.Format("%s",pView->GetDocument()->GetTitle());
AfxMessageBox(test);//此处测试结果表明找到所要切换 view
//CMDIChildWnd* childWnd = (CMDIChildWnd*)((CFrameWnd*)AfxGetApp()->m_pMainWnd)->GetActiveFrame();
//childWnd->SetActiveView(pView);
//childWnd->RecalcLayout();
if(!pView->IsKindOf(RUNTIME_CLASS( CLView)))
SetActiveView(pView);
RecalcLayout();
}
}
}
我运行程序的时候,不能实现根据名字激活
并且程序关闭的时候出现警告:
应用程序发生异常unknown software exception (0x80000003),位置为0x77f813b1。
void CMainFrame::OnActiveView()
{
// TODO: Add your command handler code here
POSITION pos = ((CLApp*)AfxGetApp())->pDocTemplate->GetFirstDocPosition();
while (pos != NULL)
{
CLDoc* pDoc =(CLDoc*)((CLApp*)AfxGetApp())->pDocTemplate->GetNextDoc(pos);
if(pDoc->GetTitle() == "encode")//encode比如我想机会文档名为encode 的窗口
{
POSITION pos1 = pDoc->GetFirstViewPosition();
CView* pView = pDoc->GetNextView(pos1); CString test;
test.Format("%s",pView->GetDocument()->GetTitle());
AfxMessageBox(test);//此处测试结果表明找到所要切换 view
//CMDIChildWnd* childWnd = (CMDIChildWnd*)((CFrameWnd*)AfxGetApp()->m_pMainWnd)->GetActiveFrame();
//childWnd->SetActiveView(pView);
//childWnd->RecalcLayout();
if(!pView->IsKindOf(RUNTIME_CLASS( CLView)))
SetActiveView(pView);
RecalcLayout();
}
}
}
CDocument* OpenDocByStr(CString strDocName)
{
CString strDocNameTemp;
POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
CDocTemplate* m_pDocTemplate = NULL;
while(pos != NULL)
{
m_pDocTemplate = AfxGetApp()->GetNextDocTemplate(pos);
m_pDocTemplate->GetDocString(strDocNameTemp, CDocTemplate::fileNewName);
if(strDocNameTemp == strDocName)
{
return m_pDocTemplate->OpenDocumentFile(NULL);
}
}
return NULL;
}
然后:
void CMainFrame::OnQuerytmplSetting()
{
// TODO: 在此添加命令处理程序代码
CWaitCursor wait; if(::IsWindow(m_hQueryTempFrm))
{
CFrameWnd* pFrm = (CFrameWnd*)FromHandle(m_hQueryTempFrm);
ASSERT(pFrm != NULL); pFrm->ActivateFrame();
}
else
{
CDocument* pDoc = OpenDocByStr(_T("QuryTempl"));
ASSERT(pDoc != NULL);
pDoc->SetTitle(_T("设置")); CView* pView = CMFC::GetViewFromDoc(pDoc);
ASSERT(pView != NULL); m_hQueryTempFrm = pView->GetParentFrame()->GetSafeHwnd();
}
}QuryTempl这个名字要在String table 中去设置,参照系统生成的VIEW来写就可以了。