In most cases, there is only one aspects connected to the document. We can find in the VC programming environment, which is very convenient to turn on multiple windows on an interface. We can make a window control view, and another window is specifically displayed. There are several ways to applying a framework representing a multi-purpose, including splitting windows and MDI sub-windows. Splitting windows look like a special frame window, including several views in each window. The application can be divided on the window when you create, or you can divide the window by selecting a menu command or dragging the split box in the slot window. After the window is cut, the user can adjust the relative dimensions of the window by mouse movement. Splitting windows are suitable for SDI applications and apply to MDI applications.
Splitting windows are implemented by class CSPLitterWnd. For Windows, CSPLitterWnd is a real window that fully occupies the user area of the frame window, and the window occupies the window area of the cut window. The segmentation window does not participate in the command transfer mechanism.
Split window has two ways of dynamic splitting and static separation. The dynamic split window allows the user to separate the window at any time, that is, you can separate the window by selecting a menu item, or separate the window by a split frame in the scroll bar. The window in the dynamic split window is usually used by the same view class. When the docking window is created, the upper left window is usually initialized into a special view. In the dynamic split window, the scroll bar is shared in the view. For example, in a window with only one horizontal segmentation, the bottom roller is simultaneously controlled with two or lower views. For a static docking window, the window has been made when the window is created, and the user can move the window, but it is impossible to merge or restart the window. The static diversity window allows you to use multiple views, and you can configure these views when creating. In a static cut window, each window has its own scroll bar. To make a static segmentation window with a scroll bar, you can add WS_HSCROLL and WS_VSCROLL style to DWStyle.
The following example will be described in detail below.
The first step: establish a single-window-based project TEST. All of the default values.
Step 2: Overload the virtual function oncreateclient in class cmainframe, generate virtual functions
Virtual Bool OncreateClient (LPCReatestruct LPCS, CCReateContext * PCONText);
Define variables csplitterwnd m_wndsplitter in class CMAINFRAME;
Step 3: Generate a CFormView class. The analysis is as follows: The CFormView class is a very useful class with a number of non-mode dialogs. Like CDIALOG derived class, CFormView's derived class is also linked to the corresponding dialog resource. The framework characteristics of the format are defined in the dialog resource, and all the controls it contains. The CFormView class also supports DDX and DDV. Use a dialog to generate a CFormView class, this dialog is set as follows:
Style = child
Border = none
Visible = Not selected
Define a dialog that is set by the above requirements. Define its corresponding class CVIEW1, the base class is CFormView. Set up a button IDD_BUTTON1, IDC_BUTTON2, IDC_BUTTON3. In the same way, CVIEW2 is added.
Step 4: Add the following code in OnCreateClient:
Bool CMAINFRAME :: OnCreateClient (lpcreateStruct LPCS, CCReateContext * PContext)
{
BOOL RET = M_Wndsplitter.createStatic (this, 3, 1);
RET | = m_wndsplitter.createView (1,0, runtime_class (ctestView), CSIZE (100, 100), PCONTEXT); RET | = m_wndsplitter.createView (0, 0, Runtime_Class (CView1), CSIZE (100, 200), PCON text);
RET | = m_wndsplitter.createView (2,0, runtime_class (cView2), CSIZE (100, 100), PCONText);
Return Ret;
}
At this point, a plurality of views can be generated.
Step 5: Add function functions. Implementation In CVIEW1, click Button1 to implement the drawing, the write function is as follows:
Void cView1 :: onbutton1 ()
{
File: // Get a pointer of a splitterview
CTestView * pView = (CTestView *) ((cmainframe *) AFXGETMAINWND ()) -> m_wndsplitter.getpane (1,0));
File: / / Define the DC of View
CclientDC DC (PVIEW);
DC.Moveto (10, 10);
DC.LineTo (10,100);
Dc.TextOut (10, 10, "guanximing");
}
The sixth step; realize the dimensional change of a piece. The definition function is as follows:
Void CView1 :: OnButton2 ()
{
((CMAINFRAME *) AFXGETMAINWND ()) -> M_Wndsplitter.seRowInfo (0, 4, 0));
((CMAINFRAME *) AFXGETMAINWND ()) -> m_Wndsplitter.RecLayout ());
}
Step 7: Realize the size change of the segmentation window via the keyboard, which is very convenient to change the size of the window. The write code is as follows:
Void cview1 :: onbutton3 ()
{
((CMAINFRAME *) AFXGETMAINWND ()) -> m_wndsplitter.dokeyboardsplit ());
}
Ok, now the function is realized, try it.