数据库开发之窗体编程

豆豆网   技术应用频道   2006年07月19日    社区交流

本文详细介绍数据库开发之窗体编程

  五、同(三)将如下代码:

  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.

  七、为IDR_MAINFRAME菜单新添菜单增加消息应射函数OnMenuitem32771()和OnMenuitem32772()

  八、在MainFrm.h加入:

  #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;

  作用是去掉新建选择视类对话框;

作者:李强    责编:豆豆技术应用

正在加载评论...