MDI 多个视图显示不同 我要创建多个视图,没个视图显示不同。比如点击不同菜单项,新建一个窗口,窗口显示的内容不同。 请问怎么实现?也就是一个DOc,多个View,请详细说明。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的需求sdi就可以实现了,去找找 单文档多视图切换的例子,网上很多 典型的SDI。SDI和MDI区别就在于是否多个Doc BCG里面有个BcgtabView可以满足你的需要 首先在~~App中声明CMultiDocTemplate* 指针,例如:class CJIANApp : public CWinApp{public: CJIANApp(); CMultiDocTemplate* m_pDocTemplate; CMultiDocTemplate* pFirstTemplate;.........}接着在BOOL CJIANApp::InitInstance()中把原先的 CMultiDocTemplate* m_pDocTemplate; m_pDocTemplate = new CMultiDocTemplate( IDR_JIANTYPE, RUNTIME_CLASS(CJIANDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CJIANView)); AddDocTemplate(m_pDocTemplate);改为: m_pDocTemplate = new CMultiDocTemplate( IDR_JIANTYPE, RUNTIME_CLASS(CJIANDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CJIANView)); AddDocTemplate(m_pDocTemplate); //Add an external Doctemplate pFirstTemplate = new CMultiDocTemplate( IDR_JIANTYPE, RUNTIME_CLASS(CJIANDoc), RUNTIME_CLASS(CFirstFrame), // 自己建立的以CMDIChildWnd为基类 RUNTIME_CLASS(CJIANView1));// 自己建立的以~~View为基类由你决定 //AddDocTemplate(pFirstTemplate);并且加上头文件:#include "MainFrm.h"#include "ChildFrm.h"#include "FirstFrame.h"#include "JIANDoc.h"#include "JIANView.h"#include "JIANView1.h"接着打开两个视图的代码:void CJIANView::OnInitialUpdate() { CView::OnInitialUpdate(); // TODO: Add your specialized code here and/or call the base class CJIANDoc *pDoc=GetDocument(); ASSERT_VALID(pDoc); CMainFrame *pAppFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd; ASSERT_KINDOF(CMainFrame,pAppFrame); pDoc->pChildFrame=(CChildFrame *)GetParentFrame(); CMultiDocTemplate *pFirstTemplate=((CJIANApp *)AfxGetApp())->pFirstTemplate; ASSERT_VALID(pFirstTemplate); pDoc->pFirstFrame=(CFirstFrame *)pFirstTemplate->CreateNewFrame(pDoc,pAppFrame); pFirstTemplate->InitialUpdateFrame(pDoc->pFirstFrame,pDoc);}//加上必要的头文件是不可少的#include "JIANDoc.h"#include "JIANView.h"#include "JIANView1.h"#include "MainFrm.h"//用来打开另外的一个视图void CJIANView::OpenCodeList(){ CJIANDoc *pDoc=GetDocument(); if(pDoc->haveclose==0){ POSITION pos; pos=pDoc->GetFirstViewPosition(); CView * pView; while(pos!=NULL){ pView=pDoc->GetNextView(pos); if(pView->IsKindOf(RUNTIME_CLASS(CJIANView1))){ pView->GetParentFrame()->ActivateFrame(); return; } } } ASSERT_VALID(pDoc); CMainFrame *pAppFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd; CMultiDocTemplate *pFirstTemplate=((CJIANApp *)AfxGetApp())->pFirstTemplate; pDoc->pFirstFrame=(CFirstFrame *)pFirstTemplate->CreateNewFrame (pDoc,pAppFrame); pFirstTemplate->InitialUpdateFrame(pDoc->pFirstFrame,pDoc); pDoc->haveclose=0;}class CJIANDoc : public CDocument{protected: // create from serialization only CJIANDoc(); DECLARE_DYNCREATE(CJIANDoc)// Attributespublic: CChildFrame *pChildFrame; CFirstFrame *pFirstFrame;}并且加上头文件 #include "ChildFrm.h"#include "FirstFrame.h"////////用CJIANView1视图时打开CJIANView视图void CJIANView1::OpenMapList(){ CJIANDoc *pDoc=(CJIANDoc *)GetDocument(); POSITION pos; pos=pDoc->GetFirstViewPosition(); CView * pView; while(pos!=NULL){ pView=pDoc->GetNextView(pos); if(!pView->IsKindOf(RUNTIME_CLASS(CJIANView1))){ pView->GetParentFrame()->ActivateFrame(); return; } } } dengxuxing: 你的代码中FirstFrame和JIANView1,都是怎么得来的啊?自己建的继承childframe和view类? MFC多文档平铺可以自定义么 使用UpdateLayeredWindow创建异形窗口所遇到的奇怪问题 找抽帖---我觉得<深入浅出MFC>并不如传说中的NB... 把编辑框的数据输入到列表框中 用鼠标或键盘把焦点切换到不属于同一个线程的窗口时,这个鼠标或键盘消息会被RIT放到哪个线程中? 有关sp5安装的问题。 137 端口 是哪个程序用的? com中如果处里字符串如输入和返回字符串呢? 新手求助!怎么在自己建的类里使用GetDC()啊? 定时器的问题。。。有一个定时器Kill不了。。 关于ActiveX控件和和标准控件的缩放的实现! 如何移动文件到指定路径?
SDI和MDI区别就在于是否多个Doc
class CJIANApp : public CWinApp
{
public:
CJIANApp();
CMultiDocTemplate* m_pDocTemplate;
CMultiDocTemplate* pFirstTemplate;
.........
}
接着在BOOL CJIANApp::InitInstance()中把原先的
CMultiDocTemplate* m_pDocTemplate;
m_pDocTemplate = new CMultiDocTemplate(
IDR_JIANTYPE,
RUNTIME_CLASS(CJIANDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CJIANView));
AddDocTemplate(m_pDocTemplate);
改为:
m_pDocTemplate = new CMultiDocTemplate(
IDR_JIANTYPE,
RUNTIME_CLASS(CJIANDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CJIANView));
AddDocTemplate(m_pDocTemplate); //Add an external Doctemplate pFirstTemplate = new CMultiDocTemplate(
IDR_JIANTYPE,
RUNTIME_CLASS(CJIANDoc),
RUNTIME_CLASS(CFirstFrame), // 自己建立的以CMDIChildWnd为基类
RUNTIME_CLASS(CJIANView1));// 自己建立的以~~View为基类由你决定
//AddDocTemplate(pFirstTemplate);
并且加上头文件:
#include "MainFrm.h"
#include "ChildFrm.h"
#include "FirstFrame.h"
#include "JIANDoc.h"
#include "JIANView.h"
#include "JIANView1.h"接着打开两个视图的代码:
void CJIANView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CJIANDoc *pDoc=GetDocument();
ASSERT_VALID(pDoc);
CMainFrame *pAppFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame,pAppFrame);
pDoc->pChildFrame=(CChildFrame *)GetParentFrame();
CMultiDocTemplate *pFirstTemplate=((CJIANApp *)AfxGetApp())->pFirstTemplate; ASSERT_VALID(pFirstTemplate);
pDoc->pFirstFrame=(CFirstFrame *)pFirstTemplate->CreateNewFrame(pDoc,pAppFrame);
pFirstTemplate->InitialUpdateFrame(pDoc->pFirstFrame,pDoc);
}
//加上必要的头文件是不可少的
#include "JIANDoc.h"
#include "JIANView.h"
#include "JIANView1.h"
#include "MainFrm.h"
//用来打开另外的一个视图
void CJIANView::OpenCodeList()
{
CJIANDoc *pDoc=GetDocument();
if(pDoc->haveclose==0){
POSITION pos;
pos=pDoc->GetFirstViewPosition();
CView * pView;
while(pos!=NULL){
pView=pDoc->GetNextView(pos);
if(pView->IsKindOf(RUNTIME_CLASS(CJIANView1))){
pView->GetParentFrame()->ActivateFrame();
return;
}
}
}
ASSERT_VALID(pDoc);
CMainFrame *pAppFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd;
CMultiDocTemplate *pFirstTemplate=((CJIANApp *)AfxGetApp())->pFirstTemplate;
pDoc->pFirstFrame=(CFirstFrame *)pFirstTemplate->CreateNewFrame (pDoc,pAppFrame);
pFirstTemplate->InitialUpdateFrame(pDoc->pFirstFrame,pDoc);
pDoc->haveclose=0;
}class CJIANDoc : public CDocument
{
protected: // create from serialization only
CJIANDoc();
DECLARE_DYNCREATE(CJIANDoc)// Attributes
public:
CChildFrame *pChildFrame;
CFirstFrame *pFirstFrame;
}
并且加上头文件
#include "ChildFrm.h"
#include "FirstFrame.h"
////////用CJIANView1视图时打开CJIANView视图
void CJIANView1::OpenMapList()
{
CJIANDoc *pDoc=(CJIANDoc *)GetDocument();
POSITION pos;
pos=pDoc->GetFirstViewPosition();
CView * pView;
while(pos!=NULL){
pView=pDoc->GetNextView(pos);
if(!pView->IsKindOf(RUNTIME_CLASS(CJIANView1))){
pView->GetParentFrame()->ActivateFrame();
return;
}
}
}
你的代码中FirstFrame和JIANView1,都是怎么得来的啊?自己建的继承childframe和view类?