急!急!急!如何创建单文档多视图

cx0998 2002-05-10 08:25:37
我创建的新视必须基于CFormView类,但我却不知如何做。如果是基于CEditView类是很容易的,但用同样的方法却不能实现基于CFormView类或是CRecordView类,请各位VC高手不吝赐教,谢谢!·
...全文
16 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xlt777 2002-05-11
将你的要求具体再提具体些,我可能有办法解决的。
回复
wolfliu 2002-05-11
刚才忘了,MDI 程序建立多视图是很容易的,各个视图
也容易排列,SDI 就很难了
回复
wolfliu 2002-05-11
我认为 实现方式是建立 MDI 程序
当打开或建立一个文档后,程序就控制再打开或者建立新的问档时,
关闭原来的文档。
关闭一个文档时要么打开,要么建立一个新文档要么打开一个文档
回复
expert_zh 2002-05-11
This article was contributed by Chris Kirby.
I think there is a new/simpler way to create new views attached to an existing document using VC++ 5.0. I think it is a cleaner implementation since it uses new hooks that MFC provides rather than having to work with the CCreateContext's.

Assuming the following are already declared in the app:


CMultiDocTemplate * m_pTemplate;
CWhateverDocument * m_pDocument;

The app would only need to have the following to create a new view attached to the document:


void CWhateverApp::OnCreateView()
{
// creates the frame and associated view, attaches to document
CFrameWnd * pFrameWnd = m_pTemplate->CreateNewFrame( m_pDocument, NULL );

// error checking in case creation of frame or view fails
RETURN_ON_NULL( pFrameWnd );

// let the frame do any initialization the framework needs,
// call the view's OnInitialUpdate()
m_pTemplate->InitialUpdateFrame( pFrameWnd, m_pDocument );
}


回复
expert_zh 2002-05-11
This article was contributed by Adrian Roman.
I add here the code that could be used to add multiple views to a document, in a MDI application. I usually make database applications, and I don't want that the document to be created/destroyed by the framework, so I create the document myself (and of course I destroy it J ), and in document's constructor I set the m_bAutoDelete flag to FALSE.

The CMyApp class contains as public member a pointer to my document. I also make document templates for all views, and I keep the pointers in CMyApp. You should have something like this in InitInstance():


m_pView1Templ=new CMultiDocTemplate( IDR_VIEW1TYPE,
RUNTIME_CLASS( CMyDoc ),
RUNTIME_CLASS( CChildFrame ),
RUNTIME_CLASS( CView1 ) );
AddDocTemplate(m_pView1Templ);
// m_pView1Templ is member of CMyApp

After you created all necessary document templates, add the following code:


// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
mp_doc=new CTimeClkDoc;
mp_doc->SetTitle("Just a demo");
CCreateContext context;
context.m_pCurrentDoc=mp_doc;
context.m_pNewViewClass=NULL;
context.m_pNewDocTemplate=NULL;
context.m_pLastView=NULL;
context.m_pCurrentFrame=NULL;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,NULL, &context ))
return FALSE;
m_pMainWnd = pMainFrame;

This code will allow opening the application without any open view and also avoids the dialog box that asks to choose a document template. Add for each view command handlers similar with this one:


void CMyApp::OnView1()
{
// TODO: Add your command handler code here
CChildFrame* pFrame = new CChildFrame();
CCreateContext context;
context.m_pCurrentDoc=mp_doc; //that's the way I avoid to create new document every time I open a new view
context.m_pNewViewClass=RUNTIME_CLASS(CView1);
context.m_pNewDocTemplate=m_pView1Templ;
context.m_pLastView=(((CMainFrame *)m_pMainWnd)->GetActiveFrame() ? ((CMainFrame *)m_pMainWnd)->GetActiveFrame()->GetActiveView() : NULL);
context.m_pCurrentFrame=((CMainFrame *)m_pMainWnd)->GetActiveFrame();
if (!pFrame->LoadFrame(IDR_VIEW1TYPE,WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE ,m_pMainWnd, &context ))return;
pFrame->InitialUpdateFrame(mp_doc,TRUE);
}


回复
onlynight 2002-05-11
可否说一下要实现些什么功能
CEditView也是人写出来的啊
回复
ryan_chen 2002-05-11
可以。
需要自己建视,文档,菜单等等,用OpenDocumentFile来显示一个新的FormView.
具体就很长了。
不算太繁琐。
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2002-05-10 08:25
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……