MFC: View document Column

Source: Internet
Author: User

 Sometimes we want to implement multiple views on the single document interface. The implementation method is to split the interface of the original document and separate it in the form of N rows and M columns, of course, segmentation can also be performed recursively. After one split, we can try again on one of the already split attempts.

The following example splits a single document interface into four parts. Shows the effect.


The split step is to first split the column into one row and two columns, and then split the second column into three rows and one column (note that the column and column numbers start from 0, the second column we are talking about is actually 1 column, and the first column is 0)

The following describes the implementation method.

1 first, we create four dialogs with the ID idd_tree1 idd_list1 idd_tree2 idd_list2Note: Select child for the style in the dialog box.

   2. Create four view classes. Here, let the four view classes inherit from formview (in this way, you can add controls on the above ).

      Clist1view Inherited from formview Association dialog box idd_list1


Clist2view Inherited from formviewAssociation dialog box idd_list2

     Ctree1view Inherited from formviewAssociation dialog box idd_tree1

    Ctree2view Inherited from formviewAssociation dialog box idd_tree2

  3Add two variables to the cmainframe class. The type isCsplitterwnd (for details about this type, refer to msdn)

     Csplitterwnd m_wndsplitter;
     Csplitterwnd m_wndsplitter1;

     Then add the virtual function to the cmainframe class:

     Virtual bool oncreateclient (lpcreatestruct lpcs, ccreatecontext * pcontext );

     Add the following code in the source file function implementation:

   

   Bool cmainframe: oncreateclient (lpcreatestruct lpcs, ccreatecontext * pcontext)
{
 // Todo: add your specialized code here and/or call the base class
 Crect CR;
 Getwindowrect (& Cr );
 
 // Create a static column partition window, which is divided into one row and two columns
 If (m_wndsplitter.createstatic (this, 1, 2) = NULL)
       Return false;

   // Connect treeview1 to the 0 rows and 0 columns pane
 M_wndsplitter.createview (0, 0, runtime_class (treeview1), csize (Cr. Width ()/4, Cr. Height (), pcontext );
   If (m_wndsplitter1.createstatic (& m_wndsplitter, 3,1, ws_child | ws_visible, m_wndsplitter.idfromrowcol (0, 1) = NULL)
       Return false; // separate the first column from the second row and the second column from the third row.
   // Connect the listview1 class to the 0 rows and 0 columns of the second column object
 M_wndsplitter1.createview (0, 0, runtime_class (listview1), csize (3 * Cr. Width ()/4, Cr. Height ()/3), pcontext );
   // Link the treeview2 class to the first row and column 0 of the second column object
 M_wndsplitter1.createview (1, 0, runtime_class (treeview2), csize (3 * Cr. Width ()/4, Cr. Height ()/3), pcontext );
 // Connect the listview2 class to the 2 rows and 0 columns of the second column object
 M_wndsplitter1.createview (2, 0, runtime_class (listview2), csize (3 * Cr. Width ()/4, Cr. Height ()/3), pcontext );
   Return true;

//Return cframewnd: oncreateclient (lpcs, pcontext );
}

   Add the include file in the source file header:

   # Include "list1view. H"
   # Include "list2view. H"
   # Include "tree1view. H"
   # Include "tree2view. H"

   Then run the program, and the window will be split.

Reprinted from http://blog.sina.com.cn/s/blog_760680fc0100pomn.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.