分类:
2008-10-13 16:43:14
数据库开发之窗体编程
作者:
public: CMultiDocTemplate* pDoctemp1; CMultiDocTemplate* pDoctemp2;
三、修改InitInstance()中将如下代码:
CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_MDISDITYPE, RUNTIME_CLASS(CMdisdiDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CMdisdiView)); AddDocTemplate(pDocTemplate);改为:
//CMultiDocTemplate* pDocTemplate;//删除 pDoctemp1 = new CMultiDocTemplate( IDR_MDISDITYPE, RUNTIME_CLASS(CMdisdiDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CMdisdiView)); AddDocTemplate(pDoctemp1);
四、加入新类CDoc2,基类为CDocument(利用菜单Insert-New Class…让其自动生成即可);加入新框架类CChildFrame2,基类为CMDIChildWnd;
加入新视类,这里新加CView2基类为CFormView类(Insert-New Form…),注意在添加对话框中将Document选为CDoc2;
五、同(三)将如下代码:
CMultiDocTemplate* pNewDocTemplate = new CMultiDocTemplate( IDR_VIEW2_TMPL, RUNTIME_CLASS(CDoc2), // document class RUNTIME_CLASS(CMDIChildWnd), // frame class RUNTIME_CLASS(CView2)); // view class AddDocTemplate(pNewDocTemplate);
改为:
pDoctemp2 = new CMultiDocTemplate( IDR_VIEW2_TMPL, RUNTIME_CLASS(CDoc2), // document class RUNTIME_CLASS(CChildFrame2), // frame class RUNTIME_CLASS(CView2)); // view class AddDocTemplate(pDoctemp2);并在mdisdi.cpp头部添加:
#include "Doc2.h"六、修改IDR_MAINFRAME菜单,新添一菜单“功能”,其子菜单为窗口1和窗口2.用ctrl+c复制,ctrl+v粘贴,产生二个新菜单IDR_MAINFRAME1和IDR_MAINFRAME2,再将其更名为IDR_MDISDITYPE,IDR_VIEW2_TMPL.
#include "mdisdiDoc.h" #include "Doc2.h"并在类中添加:
public: CMdisdiDoc * pDoc1; CDoc2 * pDoc2;在MainFrm.cpp增加代码如下:
void CMainFrame::OnMenuitem32771() { // TODO: Add your command handler code here if(pDoc1==NULL) { CMdisdiApp * pmdisdiapp =(CMdisdiApp *)AfxGetApp(); pDoc1=(CMdisdiDoc *) pmdisdiapp->pDoctemp1->OpenDocumentFile(NULL); } else { POSITION pos; pos=pDoc1->GetFirstViewPosition(); CView * pView; pView=pDoc1->GetNextView(pos); pView->GetParentFrame()->ActivateFrame(); } } void CMainFrame::OnMenuitem32772() { if(pDoc2==NULL) { CMdisdiApp * pmdisdiapp =(CMdisdiApp *)AfxGetApp(); pDoc2=(CDoc2 *) pmdisdiapp->pDoctemp2->OpenDocumentFile(NULL); } else { POSITION pos; pos=pDoc2->GetFirstViewPosition(); CView * pView; pView=pDoc2->GetNextView(pos); pView->GetParentFrame()->ActivateFrame(); } }
九、在MainFrm.cpp添加如下代码:
CMainFrame::CMainFrame() { pDoc1=NULL; pDoc2=NULL; }
在ChildFrm.cpp中添加:
#include "MainFrm.h"
和如下代码:
CChildFrame::~CChildFrame() { CMainFrame * pmainwnd= (CMainFrame *)AfxGetMainWnd(); pmainwnd->pDoc1=NULL; }
在ChildFrame2.cpp中添加:
#include "MainFrm.h"
和如下代码:
CChildFrame2::~CChildFrame2() { CMainFrame * pmainwnd= (CMainFrame *)AfxGetMainWnd(); pmainwnd->pDoc2=NULL; }
最后将InitInstance()中如下几行注释掉:
CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE;
作用是去掉新建选择视类对话框;
--------------------next---------------------