Static split window
To create a static split window, follow these steps:
1. Define a csplitterwnd member object in the parent framework class.
2. Reload the cframewnd: oncreateclient member function of the parent framework class.
3. Call the createstatic member function of the csplitterwnd member object in the overloaded cframewnd: oncreateclient function, and then call the createview member function of the csplitterwnd member object to create a view for each pane.
Example: in the main frame window, create a static split window with two rows and one column in the customer area: (first create an MFC single document project named "example34)
1. In the mainfrm. h file, add the member object cmainframe class: csplitterwnd m_wndsplitter ;.
2. in the Class View, find the cmainframe class, right-click, and select Properties From the shortcut menu. The property page is displayed, and then click the "overrides" button on the toolbar of the property page, the list below lists the functions that can be reloaded. Find oncreateclient to generate the reload function.
3. Find the oncreateclient function that has just been overloaded in the mainfrm. cpp file and modify it. Because no other view classes are created, the top and bottom two pane views are cexample34view. To recognize the cexample34view class, add # include "example34view. H" to the mainfrm. cpp file and add # include "example34doc. H" to the example34view. h file ". The final oncreateclient function is modified as follows:
C ++ code
- Bool cmainframe: oncreateclient (lpcreatestruct lpcs, ccreatecontext * pcontext)
- {
- // Todo: add your specialized code here and/or call the base class
- Crect RC;
- // Obtain the crect object in the client area of the Framework Window.
- Getclientrect (& rc );
- // Create a static split window with two rows and one column
- If (! M_wndsplitter.createstatic (this, 2, 1 ))
- Return false;
- // Create a view in the preceding pane
- If (! M_wndsplitter.createview (0, 0, runtime_class (cexample34view), csize (RC. Width (), RC. Height ()/2), pcontext ))
- Return false;
- // Create a view in the following pane
- If (! M_wndsplitter.createview (1, 0, runtime_class (cexample34view), csize (RC. Width (), RC. Height ()/2), pcontext ))
- Return false;
- Return true;
- // Return cframewndex: oncreateclient (lpcs, pcontext );
- }
4. Run the program and turn off other panels on the result interface. The effect is as follows:
If you want to create a nested split window in a certain pane, You need to define a csplitterwnd object and use the csplitterwnd object in the parent pane as the parent frame window to create a split window.
How to associate a subwindow with a dialog box?
Class View, right-click the project name, class wizard, and select the MFC class from the add class drop-down menu ..., enter the class name cinfoview and select cformview as the base class. infoview is automatically generated. H and infoview. CPP and automatically generate a dialog box in mainfrm. the CPP file contains the header file infoview. h
Finally, modify the above Code:
- If (! M_wndsplitter.createview (0, 0, runtime_class (cinfoview), csize (RC. Width (), RC. Height ()/2), pcontext ))
- Return false;
In this way, the subwindow above is associated with the dialog box, that is, the subwindow above displays the dialog box.
Static split window