資料庫開發之表單編程

來源:互聯網
上載者:User
 

  在很多管理資訊系統的表單都有一些共同點:可以通過架構菜單開啟各種類型的視圖視窗,而這些視圖視窗具有MDI的一些特點,可以在架構表單中最小化最大化還原等,並且點擊菜單只能產生一個視窗(象SDI)。這種形式的視窗設計給人與一種條理感。於是我用VC6.0嘗試建立這種視窗,現將整個過程為大家寫下來,這裡應含有MFC的一些內幕技術。

一、建立AppWizad(exe)工程,名為mdisdi,基於MDI的文檔視模式(其餘預設)。

二、在CApp子類中添加如下代碼:

  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.

七、為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;

作用是去掉建立選擇視類對話方塊;
代碼:http://www.vczx.com/article/file/20041011111218_vczx_mdisdi.rar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.