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);
}