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 these steps 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 bool
Createview (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 cmainframe.
Csplitterwnd m_splitterwnd;
4.
Reload the cframewnd: oncreateclient member function of the parent framework cmainframe. Edit the Code as follows:
Bool cmainframe: oncreateclient (lpcreatestruct lpcs, ccreatecontext * pcontext) {// todo: add your specialized code here and/or call the base class // obtain the size of the Main Window crect rect; getclientrect (& rect); // generate the first static split m_splitterwnd.createstatic (this, // parent window pointer 1, // number of rows 2 ); // Number of columns // generate the view m_splitterwnd.createview (1st, runtime_class (cleftview), csize (rect. width ()/4, rect. height (), pcontext); // generates a view m_splitterwnd.createview (2nd, // The row and column ordinal number of the pane runtime_class (csplitterwnddemoview) for the panes ), // View class csize (rect. width ()-rect. width ()/5, rect. height (), // initialize the pcontext size); // return true as the creation parameter of the parent window; // The oncreateclient function of the base class is no longer called // return cframewnd :: oncreateclient (lpcs, pcontext );}
Note: add the header file # 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" to the header file. Otherwise, the error "csplitterwnddemodoc" is reported'
: 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 ondraw (CDC * of the csplitterwnddemoview class *
PDC) Function
PDC-> textout (200,300, m_str_view );
3. Custom messages;