Application of split window class csplitterwnd in the dialog box and communication between Split Window

Source: Internet
Author: User

When you type "How to Use csplitterwnd in the dialog box" on Google or Baidu, most of the posts you search for are the same. It is really a dialog box-based csplitterwnd application, most of them are based on the single-document framework. For a blog post with reference value, see codeguru.

This article will show you how to use csplitterwnd in the dialog box to split the main window into two subwindows. It is only related to the View class and does not involve document classes. Reload onsize () so that the window size can change with the change of the main window.

The procedure is as follows:

1. Declare the pointer type member variables of a framework class and a csplitterwnd sharding window class in the header file of the main window class (a dialog box ).

 
PRIVATE: cframewnd * m_pframesplit; // separate the window csplitterwnd m_wndspliter; // left and right

2. initialize the oninitdialog () method or oncreate () event in the main window class implementation file, register the framework class and the initial csplitterwnd

// Obtain the crect RC in the main window; getdlgitem (idc_childwnd)-> getwindowrect (RC); // idc_childwnd is the ID of a picturebox, indicating the screentoclient (& rc) in the region to be split ); // register the framework class cstring sclass = callback (cs_vredraw | cs_hredraw,: loadcursor (null, idc_arrow), (hbrush): getstockobject (white_brush),: loadicon (null, idi_application); // create a window separation framework m_pframesplit = new cframewnd; m_pframesplit-> Create (sclass, _ T (""), ws_child, crect ), this); m_pframesplit-> movewindow (RC); m_pframesplit-> showwindow (sw_show); // create the split window m_wndspliter.createstatic (m_pframesplit, 1, 2); m_wndspliter.createview (0, 0, runtime_class (ceditview), csize (INT) (RC. width () * 0.265), 0), null); // The proportion of the Left window is 26.5% m_wndspliter.createview (0, 1, runtime_class (ceditview), csize (), null ); m_wndspliter.movewindow (0, 0, RC. width (), RC. height (); m_wndspliter.showwindow (sw_show );

Note the last three or four rows. Here is the view class corresponding to the two windows to be split. To demonstrate the effect of csplitterwnd, you can directly use ceditview instead.

Running result. The picturebox area of the main window is split into two edits.Box,There is a removable Separator in the middle to adjust the size.

3. Reload onsize () to make the window and control adaptive size. Both the control pointer and ID can be passed.

Void cmainwnddlg: onsize (uint ntype, int CX, int CY) {cdialog: onsize (ntype, CX, CY); static int nlastcx = 0; static int nlastcy = 0; int nwidth = Cx-nlastcx; int nheight = cy-nlastcy; adjustdlgitem (m_pframesplit, 0, 0, nwidth, nheight); nlastcx = Cx; nlastcy = Cy ;} // move the control to implement window adaptive void cmainwnddlg: adjustdlgitem (uint NID, int nleft, int ntop, int nright, int nbottom) {adjustdlgitem (getdlgitem (NID), nleft , Ntop, nright, nbottom);} // move the control to implement window adaptive void cmainwnddlg: adjustdlgitem (cwnd * pitem, int nleft, int ntop, int nright, int nbottom) {If (null = pitem) return; If (! Iswindow (pitem-> getsafehwnd () return; // obtain the control area crect rcwnd; pitem-> getwindowrect (& rcwnd); screentoclient (& rcwnd ); // recalculate the region rcwnd. top + = ntop; rcwnd. bottom + = nbottom; rcwnd. left + = nleft; rcwnd. right + = nright; // mobile control pitem-> movewindow (rcwnd. left, rcwnd. top, rcwnd. width (), rcwnd. height ());}

Add functions required for the split window

For more information, see "customer service ".

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.