Source code:Http://download.csdn.net/detail/nuptboyzhb/4221531
Csplitterwnd class
The csplitterwnd class provides a splitter window, which contains multiple panes. The pane is usually an application-specificCviewDerived object, but it can also be any cwnd object with an appropriate subwindow ID.
A csplitterwnd object is usually embedded into a cframewnd or javasichildwnd parent object. Follow the steps below to create a csplitterwnd object
1. embed a csplitterwnd member variable in the parent framework.
2. Reload the cframewnd: oncreateclient member function of the parent framework.
3. Call the create or createstatic member functions of the csplitterwnd class from the overloaded oncreateclient function.
3.1 call the create member function to createDynamic.
3.2 you can use the createstatic member function to createStaticSeparator window.
4. Call the createview member function of csplitterwnd class from the overloaded oncreateclient function;
Important functions:
BoolCreate (cwnd * pparentwnd,
Int nmaxrows,
Int nmaxcols,
Size sizemin,
Ccreatecontext * pcontext,
DWORD dwstyle = ws_child | ws_visible | ws_hscroll | ws_vscroll | spls_dynamic_split,
Uint nid = afx_idw_pane_first
);
Return Value: If successful, a non-zero value is returned; otherwise, 0 is returned.
Parameters:
Pparentwnd |
The parent frame window of the splitter window. |
Nmaxrows |
The maximum number of rows in the splitter window. The value cannot exceed 2. |
Nmaxcols |
The maximum number of columns in the splitter window. The value cannot exceed 2. |
Sizemin |
Specifies the minimum size required to display a pane. |
Pcontext |
Pointer to a ccreatecontext structure. In most cases, this value can be passed to the parent Framework Window.Pcontext. |
Dwstyle |
Specify the window style. |
Nid |
The ID of the subwindow. If the separator window is not nested in another separator window, the ID can be afx_idw_pane_first. |
BoolCreatestatic (cwnd * pparentwnd,
Int nrows,
Int ncols,
DWORD dwstyle = ws_child | ws_visible,
Uint nid = afx_idw_pane_first
);
Return Value: If successful, a non-zero value is returned; otherwise, 0 is returned.
Parameters:
Pparentwnd |
The parent frame window of the splitter window. |
Nrows |
Number of rows. The value must not exceed 16. |
Ncols |
Number of columns. The value must not exceed 16. |
Dwstyle |
Specify the window style. |
Nid |
The ID of the subwindow. If the separator window is not nested in another separator window, the ID can be afx_idw_pane_firsh. |
Virtual boolCreateview (INT row, int Col, cruntimeclass * pviewclass, size sizeinit, ccreatecontext * pcontext );
Return Value: If successful, a non-zero value is returned; otherwise, 0 is returned.
Parameters:
Row |
Specifies the window line of the splitter used to place the new view. |
Col |
Specifies the splitter window column used to place the new view. |
Pviewclass |
Specify the cruntimeclass of the new view. |
Sizeinit |
Specify the initial size of the new view. |
Pcontext |
Pointer to the Creation environment used to create this view (generally, this pcontext is passed to the oncreateclient member function of the parent framework in which this separator window is created ). |
Note: The third parameter cruntimeclass is runtime_class (Class Name). If this class is a resource class, the parent class of this class must be cformview,
Example:
1. Create a single-document application named splitterwnddemo;
2. Insert resources in a dialog box as a split window, and add corresponding controls to the dialog box;
2.1 Set Properties of the dialog box: Set'Style'Set'Lower ';DisableTitle bar;Border selection'Resize'; Other formats are not set at the moment;
2. 2Create a class for the dialog box, Class Name: cleftview; parent class:Cformview;
3. embed a csplitterwnd member variable in the cmainframe.
Csplitterwnd m_splitterwnd;
4. Reload the cframewnd: oncreateclient member function of the cmainframe of the parent framework. Edit the Code as follows:
1 bool cmainframe: oncreateclient (lpcreatestruct lpcs, ccreatecontext * pcontext) 2 3 {4 5 // todo: add your specialized code here and/or call the base class 6 7 // obtain the size of the Main Window 8 9 crect rect; 10 11 getclientrect (& rect ); 12 13 // generate the first static split 14 15 m_splitterwnd.createstatic (this, // parent window pointer 16 17 1, // number of rows 18 19 2 ); // Number of columns 20 21 // a 1st pane generates view 22 23 m_splitterwnd.createview (, 24 25 runtime_class (cleftview), 26 27 csize (rect. width ()/4, rect. height (), 28 29 pcontext); 30 31 32 // generates a view 33 34 m_splitterwnd.createview (2nd, // The number of rows and columns in the pane 35 36 runtime_class (csplitterwnddemoview), // View Class 37 38 csize (rect. width ()-rect. width ()/5, rect. height (), // initialization size 39 40 pcontext); // The creation parameter of the parent window 41 42 return true; // no longer calls the oncreateclient function of the base class 43 44 // return cframewnd: oncreateclient (lpcs, pcontext); 45 46}
Note: Add header files.
# Include "splitterwnddemoview. H"
# Include "leftview. H"
Because csplitterwnddemoview is the view class of the application, add the header file of the document class # include "splitterwnddemodoc. H ", otherwise, an error is returned: 'csplitterwnddemodoc ': Missing storage-class or type specifiers
Now, the interface has been completed
========================================================== ==========================================================
Data transmission between Split windows:
I.ApplicationDocument TypeData Transmission
For each class derived from the View class, you can call cview: getdocument to obtain the pointer of the current application document class and then convert the type. Note, include the header file of the document class;
Example: (continue programming the above application)
1. Add a member variable m_str of the cstring type to the document class;
2.CleftviewAdd a button control and an edit box control. associate a cstring member variable with the edit box control. Add a message response function to the button control and edit the Code as follows:
Updatedata ();
Csplitterwnddemodoc * pdoc = (csplitterwnddemodoc *) getdocument (); // get the document
Pdoc-> m_str = m_edit_data; // transmit data
Pdoc-> updateallviews (null); // update all views
3. Edit the code in csplitterwnddemoview: ondraw (CDC * PDC) as follows:
Csplitterwnddemodoc * pdoc = getdocument ();
Assert_valid (pdoc );
PDC-> textout (200,200,Pdoc-> m_str);
Ii. PassObtain the pointer of the peer view, For operation Interaction
Obtain the application pointer through afxgetapp (), and then obtain the cmainframe pointer of the main framework through the Application pointer. Then, the cmainframe pointer is obtained to obtain the member variable m_splitterwnd of the csplitterwnd type of the cmainframe; call the getpane function of m_splitterwnd;
1. Add a member variable m_str_view of the cstring type to the View class;
2.CleftviewAdd a button control. The editing code is as follows:
Csplitterwnddemoapp * PAPP = (csplitterwnddemoapp *) afxgetapp (); // obtain the application pointer
Cmainframe * pframe = (cmainframe *) PAPP-> m_pmainwnd; // obtain the pointer of the Main Frame
Csplitterwnddemoview * pview = (csplitterwnddemoview *) pframe-> m_splitterwnd.getpane (0, 1); // obtain the pointer of the View class
Pview-> m_str_view = m_edit_data; // Data Transmission
Pview-> invalidate (); // redraw the view
Note: add the header file of the corresponding class:
# Include "mainfrm. H"
# Include "splitterwnddemoview. H"
3. Modify the ondraw (CDC * PDC) function of the csplitterwnddemoview class
PDC-> textout (200,300, m_str_view );
3. Custom messages;
From: http://blog.csdn.net/nupt123456789/article/details/7455471