我的程序中有两个视图,我希望在弹出一个对话框之后,激活另外一个new视图,而hide掉old视图,该怎么做?关键问题是:对话框弹出之后,old视图已经处于不被激活的状态,这种情况下如何得到old视图的指针,并且将之hide掉!希望我已经说明白了,谢谢关注!
解决方案 »
- VC界面调试时,为什么看不到界面,代码和界面不能同时看???
- MFC Commbox.SetForce()不起作用--推荐
- 知道SOCKET号,如何获取其用WSAEventSelect()绑定的事件句柄?
- vc调用com组件的问题,谢谢回答,回者有分
- 如何实现ListView的类似于WinXP中资源管理器的效果?
- 借人气问个Ollydbg调试的问题~~高手赐教
- 一个文本框的入门级问题
- 请问如何使文本框控件显示CString数实现据实现自动滚屏?
- 100分求助:文件拷贝问题,急待解决!!!!!
- 谁有用VB编写的多点传送文件的FTP源程序?Thank you!
- 如何扫描硬件,判断某个硬件是否真实存在?
- 树的问题
可以用GetActiveView()的!
pView=GetActiveView();
{
CView *pOldActiveView =GetActiveView();
CView *pNewActiveView=(CView*)GetDlgItem(nForm);
if(pNewActiveView==NULL)
{
switch(nForm)
{
case IDD_MULTISCREEN_FORM1:
pNewActiveView=new CView1();
break;
case IDD_MULTISCREEN_FORM2:
pNewActiveView=new CView2();
break;
case IDD_MULTISCREEN_FORM3:
pNewActiveView=new CView3();
break;
case ID_MainView:
pNewActiveView=new CMultiScreenView();
break;
}
CCreateContext context;
context.m_pCurrentDoc=pOldActiveView->GetDocument();
//add the flag:WS_BORDER,or the view will capture all the client included the windowrect!
pNewActiveView->Create(NULL,NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,CFrameWnd::rectDefault,this,nForm,&context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
//I use the win32 based function:SetWindowLong() instead of the older style:SetWindowWord()
::SetWindowLong(pNewActiveView->m_hWnd,GWL_ID,AFX_IDW_PANE_FIRST);
this->RecalcLayout();
delete pOldActiveView;
}
请给Email.
我的Email为[email protected]
代码如下
void CMainFrame::CreateOrActivateFrame(CDocTemplate* pTemplate,CRuntimeClass* pViewClass)
{
CMDIChildWnd* pMDIActive=MDIGetActive();//获得当前激活的子窗口
if (pMDIActive==NULL)
{
MessageBox(_T("没有打开的文档类!"));
::PostQuitMessage(0);
return;
}
WINDOWPLACEMENT WndStatus;
CRect rect;
rect.left=0;
rect.top=0;
rect.bottom=200;
rect.right=200;
WndStatus.rcNormalPosition=rect;
pMDIActive->SetWindowPlacement(&WndStatus);
CDocument* pDoc=pMDIActive->GetActiveDocument();//获得当前激活的文档
ASSERT(pDoc!=NULL);
CView* pView;
POSITION pos=pDoc->GetFirstViewPosition();
while(pos!=NULL)
{
pView=pDoc->GetNextView(pos);
if (pView->IsKindOf(pViewClass))
{
pView->GetParentFrame()->ActivateFrame();
//激活pViewClass 指向的视图
return;
}
}
//用当前文档模板创建新视图并激活
CMDIChildWnd* pNewFrame=(CMDIChildWnd*)(pTemplate->CreateNewFrame
(pDoc,NULL));
if (pNewFrame==NULL)
return;
ASSERT_KINDOF(CMDIChildWnd,pNewFrame);
pTemplate->InitialUpdateFrame(pNewFrame,pDoc);
// MDITile(MDITILE_HORIZONTAL);
}
在你想要的地方调用
CreateOrActivateFrame(AfxGetApp()->m_pDocTemplate,CRuntimeCLass(CYourView))就可以了,
m_pDocTemplate是和你的CYourView相关的文档模板类的对象
http://www.codeproject.com/docview/switchingviews.asp
我需要这样的代码
谢谢
循环浏览已经打开的文档
使用CDocTemplate中的GetFirstDocPosition()和GetNextDoc()函数。 应用程序中循环浏览已经打开的视
CDocument 中的 GetFirstViewPosition() 和 GetNextView() 函数。
MDI和SDI切换有很大的区别吗