Use csplitterwnd to split the window

Source: Internet
Author: User
Tags dedicated ip

Use csplitterwnd to split the window

 

I. basic use of csplitterwnd

1. Add a csplitterwnd member to cmainframe:
 Csplitterwnd m_splitterwnd1;

2. Create two new view classes based on cview, cviewleft and cviewright. One is used for display on the left and the other is used for display on the right.


3. Reload the oncreateclient function of cmainframe,
Call the createstatic function of csplitterwndr to create the split window. The createview function creates two views left and right, and setcolumninfo sets the column width of the split window:
  Bool cmainframe: oncreateclient (lpcreatestruct lpcs, ccreatecontext * pcontext)
  {
    // Todo: Add a dedicated IP address hereCodeAnd/or call the base class
    M_mysplitter1.createstatic (this, 1, 2 );       // Create a split window with one row and two columns
    M_mysplitter1.createview (0, 0, runtime_class (cviewleft), csize (0, 0 ),
      Pcontext );     // Create a view with 0th rows and 0th Columns
    M_mysplitter1.createview (0, 1, runtime_class (cviewright), csize (0, 0 ),
      Pcontext );     // Create a view with 0th rows and 1st Columns

  M_mysplitter1.setcolumninfo (0,250, 10 );   // Set the width of a column. Here, the ideal width of The 0th column is set to 250 pixels, and the minimum width is 10 pixels (what is the minimum width? Not clear)

  Return true;

  // Return cframewnd: oncreateclient (lpcs, pcontext );
 }
 
 After running the command, a window is generated, which is divided into two views: left and right.

 

2. Add functions required for the split window
  A new class is derived from the csplitterwnd class of the system.
  Right-click the Class View, select "add"-> "class", select the MFC class in the pop-up window, and enter the name of the new class cmysplitter, select cwnd as the base class (here, the base class option does not contain csplitterwnd, so select cwnd first ). Then, change "cwnd" of the generated mysplitter. h and mysplitter. cpp to "csplitterwnd ".
  Mysplitter. hMedium:
    Class cmysplitter: Public csplitterwnd
  Mysplitter. cppMedium:
    Implement_dynamic (cmysplitter, csplitterwnd)
    Begin_message_map (cmysplitter, csplitterwnd)
   
1. Double-click the separation bar to expand or collapse the column on the left.
  The onlbuttondblclk function is reloaded:
  Void cmysplitterwnd: onlbuttondblclk (uint nflags, cpoint point)
  {
    // Todo: Add message processing hereProgramCode and/or call Default Value

    // Csplitterwnd: onlbuttondblclk (nflags, point );
    Int left, min;
    Getcolumninfo (0, left, min );       // Obtain the width of column 0th (that is, the left column ).
    If (Left = 0 | left = min)       // If the current status is collapsed
    {
      Setcolumninfo (0,250, 10 );     // Reset the width of the left column, which is set to 250, that is, expand
    }
    Else
    {
      Setcolumninfo (0, 0, 10 );     // Reset the width of the left column, which is set to 0, that is, collapse
    }
    Recalclayout ();                 // Re-build the window layout
  }
 
2. Set the width of the separator bar
  In the constructor of cmysplitter (the width is set to 11 pixels here ):
  M_cxsplittergap = 11;
  M_cxsplitter = 11;    
  Meanings of several variables:
// Int m_cxsplitter, m_cysplitter; // size of splitter bar
// Int m_cxbordershare, m_cybordershare; // space on either side of Splitter
// Int m_cxsplittergap, m_cysplittergap; // amount of space between panes
// Int m_cxborder, m_cyborder; // borders in client area

3. Do not drag the separator bar.
(1) Reload the onlbuttondown function and change it to nothing:
  Void cmysplitter: onlbuttondown (uint nflags, cpoint point)
  {
// Todo: add the message processing program code and/or call the default value here
// Csplitterwnd: onlbuttondown (nflags, point );
  }
(2) The onmousemove function is reloaded and nothing is done:
  Void cmysplitter: onmousemove (uint nflags, cpoint point)
  {
// Todo: add the message processing program code and/or call the default value here

// Csplitterwnd: onmousemove (nflags, point );  
 }

 

4. Add a "button" on the separator bar
(1) import two bitmap Resources in the resource view, which is divided into a left arrow and a right arrow. The image size is (6*31) pixels: idb_bitmap_left, idb_bitmap_right
(2) Add members related to the "button" to the cmysplitter class:
Cbitmap m_bitmapleft; // Left arrow bitmap
Cbitmap m_bitmapright; // Right arrow bitmap
CDC m_dcmem; //
Crect m_rectimgbtn; // Display the rectangular area of the button
(3) Add a member function to display the rectangular area of the button:
// This function is used to obtain the rectangular area where the button is displayed.
Void cmysplitter: getimgbtnrect (void)
{
Crect R;
Int left, min;
Getwindowrect (& R );
Getcolumninfo (0, left, min );
M_rectimgbtn.setrect (left + 2 + 2, R. Height ()/2-16,
Left + 2 + 8, R. Height ()/2 + 15 ); // This is determined by the separation bar displayed in WindowsXP. Use the drawing software to test it.
If (Left = 250) // The left column of the normal display is 250 pixels wide.
{
If (m_dcmem! = NULL)
{
M_dcmem.selectobject (m_bitmapleft ); // Select the picture from the left arrow for this DC
}
}
Else
{
If (m_dcmem! = NULL)
{
M_dcmem.selectobject (m_bitmapright ); // Select the right arrow of the DC
}
}
}
(4) Reload the ondrawsplitter function and draw the button:
Void cmysplitter: ondrawsplitter (CDC * PDC, esplittype ntype,
Const crect & rect)
{
// Todo: Add dedicated code and/or call the base class here
Csplitterwnd: ondrawsplitter (PDC, ntype, rect ); // Original separation bar

If (PDC! = NULL)
{
If (m_dcmem = NULL)
{
M_dcmem.createcompatibledc (null ); // If the createcompatibledc parameter is null, the system creates a display compatible with the current display. DC
}
Getimgbtnrect ();
PDC-> bitblt (m_rectimgbtn.left, m_rectimgbtn.top,
M_rectimgbtn.width (), m_rectimgbtn.height (),
& M_dcmem, 0, 0, srccopy );// Copy the image from m_dcmem to the PDC and draw it out (this is probably the meaning)
}
}
}
(5) Reload the onlbuttonup function so that when you click this button, you can collapse or expand the left column.
Void cmysplitter: onlbuttonup (uint nflags, cpoint point)
{
// Todo: add the message processing program code and/or call the default value here
Getimgbtnrect ();
If (m_rectimgbtn.ptinrect (point) // If the mouse is currently in the "button" Area
{
// Check whether the left column is collapsed. If yes, the left column is hidden. If not, the left column is displayed.
// Use getcolumninfo and setcolumninfo
}
Else
{
Csplitterwnd: onlbuttonup (nflags, point );
}
}
(6) The onmousemove function is reloaded. When you move the mouse over the "button", the mouse shape is changed to the hand shape.
Void cmysplitter: onmousemove (uint nflags, cpoint point)
{
// Todo: add the message processing program code and/or call the default value here
Getimgbtnrect ();
If (m_rectimgbtn.ptinrect (point ))
{
: Setcursor (loadcursor (null, idc_hand ));
}
Else
{
: Setcursor (loadcursor (null, idc_arrow ));
}
}

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.