Form programming for database development

Source: Internet
Author: User

In many forms of management information systems, there are some similarities: You can open various types of View windows through the framework menu, and these View windows have some characteristics of MDI, you can minimize the maximization of restoration in the frame form, and click the menu to generate only one window (such as SDI ). This form of window design gives people a sense of organization. So I used VC6.0 to try to create such a window. Now I will write down the entire process. Here, we should include some insider technologies of MFC.

1. Create an AppWizad (exe) project named mdisdi. the MDI-based document mode is used (default for other projects ).

2. Add the following code to the Child class of CApp:

Public:
CMultiDocTemplate * pDoctemp1;
CMultiDocTemplate * pDoctemp2;

3. Modify InitInstance () with the following code:

  CMultiDocTemplate* pDocTemplate;  pDocTemplate = new CMultiDocTemplate(       IDR_MDISDITYPE,       RUNTIME_CLASS(CMdisdiDoc),       RUNTIME_CLASS(CChildFrame), // custom MDI child frame       RUNTIME_CLASS(CMdisdiView));   AddDocTemplate(pDocTemplate);

Changed:

// CMultiDocTemplate * pDocTemplate; // Delete pDoctemp1 = new CMultiDocTemplate (partition, RUNTIME_CLASS (CMdisdiDoc), RUNTIME_CLASS (CChildFrame), // custom MDI child frame RUNTIME_CLASS (CMdisdiView )); addDocTemplate (pDoctemp1 );

4. Add the New Class CDoc2 and the base Class is CDocument (use menu Insert-New Class... Make it automatically generated); Add the new framework class CChildFrame2, and the base class is javasichildwnd;
Add the New view class. Here, the base class CView2 is added as the CFormView class (Insert-New Form ...), Note that in the Add dialog box, select Document as CDoc2;

5. Same as (3), use the following code:

  CMultiDocTemplate* pNewDocTemplate = new CMultiDocTemplate(               IDR_VIEW2_TMPL,        RUNTIME_CLASS(CDoc2), // document class       RUNTIME_CLASS(CMDIChildWnd), // frame class       RUNTIME_CLASS(CView2)); // view class     AddDocTemplate(pNewDocTemplate);

Changed:

  pDoctemp2 = new CMultiDocTemplate(            IDR_VIEW2_TMPL,         RUNTIME_CLASS(CDoc2), // document class           RUNTIME_CLASS(CChildFrame2), // frame class             RUNTIME_CLASS(CView2)); // view class       AddDocTemplate(pDoctemp2);

Add the following in the mdisdi. cpp header:

       #include "Doc2.h"

6. Modify the IDR_MAINFRAME menu and add a new menu "function". Its submenus are window 1 and window 2. press ctrl + c and press ctrl + v to generate two new menus: IDR_MAINFRAME1 and IDR_MAINFRAME2, and rename them IDR_MDISDITYPE and IDR_VIEW2_TMPL.

7. Add the OnMenuitem32771 () and OnMenuitem32772 () functions to the new menu of IDR_MAINFRAME ()

8. Add in MainFrm. h:

  #include "mdisdiDoc.h"  #include "Doc2.h"

And add the following to the class:

  public:  CMdisdiDoc * pDoc1;  CDoc2 * pDoc2;

Add the following code in 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();     }  }

9. Add the following code in MainFrm. cpp:

 CMainFrame::CMainFrame()  {      pDoc1=NULL;      pDoc2=NULL;  }

Add the following in ChildFrm. cpp:

  #include "MainFrm.h"

And the following code:

 CChildFrame::~CChildFrame()  {  CMainFrame * pmainwnd=            (CMainFrame *)AfxGetMainWnd();  pmainwnd->pDoc1=NULL;  }

Add the following in ChildFrame2.cpp:

  #include "MainFrm.h"

And the following code:

 CChildFrame2::~CChildFrame2()  {  CMainFrame * pmainwnd=            (CMainFrame *)AfxGetMainWnd();  pmainwnd->pDoc2=NULL;  }

Finally, comment out the following lines in InitInstance:

  CCommandLineInfo cmdInfo;  ParseCommandLine(cmdInfo);  // Dispatch commands specified on the command line  if (!ProcessShellCommand(cmdInfo))  return FALSE;

The function is to remove the new selection class dialog box;
Code: http://www.vczx.com/article/file/20041011111218_vczx_mdisdi.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.