MFC Programmer WTL Guide (8) Separator window

Source: Internet
Author: User
Tags bool file system split

Introduced

As the resource manager that manages the file system with two separate views appears for the first time in Windows 95, the Separator window is becoming a popular interface element. MFC also has a complex powerful separator window class, but it's a bit difficult to grasp its usage, and it's closely related to the document/view framework. In the seventh chapter I'll introduce WTL's separator window, which is simpler than MFC's separator window. WTL separator windows are not as many features as MFC, but are easy to use and extend.

The example project in this chapter is the Clipspy rewritten with WTL, if you're not familiar with the program, you can now take a quick look at the contents of this chapter, because I just copied the Clipspy feature without a deep explanation of how it works, after all, this article focuses on separating the windows, not the Clipboard.

WTL Separator Window

Header file Atlsplit.h contains all WTL separator window classes, a total of three classes: Csplitterimpl,csplitterwindowimpl and csplitterwindowt, but you usually only use one of them. These classes and their basic methods are described below.

Related classes

Csplitterimpl is a template class with two parameters, one is the class name of the window interface class, and the other is a Boolean variable that represents the direction of the Separator window: True indicates a vertical direction, and false indicates a horizontal orientation. The Csplitterimpl class contains the implementation code for almost all of the separator windows, and many of its methods are overloaded, overloading these methods to draw the appearance of the splitter bar itself or to achieve other effects. The Csplitterwindowimpl class is derived from the CWindowImpl and Csplitterimpl two classes, but its code is not much, there is an empty WM_ERASEBKGND message handler function and a wm_ The size handler function is used to reposition the separator window.

The last one is the Csplitterwindowt class, which derives from the Csplitterimpl class, and its window class name is "Wtl_splitterwindow". There are also two custom data types that are typically used to replace the three classes above: Csplitterwindow is used to vertically separate windows, Chorsplitterwindow for horizontal dividers.

Create a split window

Because Csplitterwindow is derived from the CWindowImpl class, you can create a separator window just as you would create other child windows. The separator window will exist throughout the life cycle of the main frame window, and a Csplitterwindow type variable should be added to the CMainFrame class. Within the CMainFrame::OnCreate () function, you can create a separator window as a child of the main window and then set it as the Client Area window for the primary window:

LRESULT CMainFrame::OnCreate ( LPCREATESTRUCT lpcs )
{
// ...
const DWORD dwSplitStyle = WS_CHILD | WS_VISIBLE |
               WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
       dwSplitExStyle = WS_EX_CLIENTEDGE;
   m_wndSplit.Create ( *this, rcDefault, NULL,
             dwSplitStyle, dwSplitExStyle );
   m_hWndClient = m_wndSplit;
}

After you create the separator window, you can specify a window for each pane or do other necessary initialization work.

Basic methods

bool SetSplitterPos(int xyPos = -1, bool bUpdate = true)
int GetSplitterPos()

You can call the Setsplitterpos () function to set the position of the separator bar, which represents the number of pixel points of the split bar from the top boundary of the separator window (the horizontal separator window) or the left boundary (the vertical separator window). You can use the default value-1 to set the divider to the middle of the separator window, make the two panes the same size, and usually pass true to the bupdate parameter to represent the corresponding change in the size of the two panes after the separator bar is moved. Getsplitterpos () returns the position of the current divider, which is also relative to the top or left edge of the separator window.

bool SetSinglePaneMode(int nPane = SPLIT_PANE_NONE)
int GetSinglePaneMode()

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.