Using a non-modal window to generate an MDI interface

Source: Internet
Author: User

I want to generate an MDI window interface, but found that using VC is cumbersome to add a lot of runtime_class, and can not implement the main window to add feature options. That is, generate a main Outlook window, and then add multiple document windows to the main window (like the Multi-text window in office). So, write this cmdichild class. The effect is shown in figure one.

To implement this class:

First step: Generate a single document program (base class is CFormView).

Step Two: Add MDIChild.H and MDIChild.cpp two documents to the project.

Step three: Add a variable cmdichild m_child to the main window.

#include "MDIChild.H"
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
  CMainFrame();
  DECLARE_DYNCREATE(CMainFrame)
  // Attributes
public:
  CMDIChild m_Child; ///////////////////////////////
  .....
}

Step Fourth: Add M_child.initmainwnd (this) to the OnCreate () event.

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
  ......
    RECT Rect;
  SetRect(&Rect, 0,64,800, 574); // 非模子窗口的活动区域,没想出自动计算的好办法,
  m_Child.InitMainWnd(this, &Rect); //所以只能手工设置。
}

Step Fifth: Add menu Events

#include "Dlg1.H"
void CMainFrame::OnDialog1()
{
  CDlg1 *pDlg = NULL;
  char *sName = "功能1"; ////////////////////////////////
  if(!m_Child.GetClassChild(sName))
  {
    pDlg = new CDlg1;
    if(!pDlg) return;
    pDlg->Create(IDD_DIALOG1, this);
  }
  m_Child.ADD((CView*)pDlg, sName);
}

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.