Visual c ++ single-document hybrid split view

Source: Internet
Author: User
Zz

Prog 23:45:16 Read16 Comment0 Font Size:LargeMediumSmall Subscription

Recently, I wanted to create a window splitting task. I found some information on the Internet and finally made a little bit more visible than Hulu. Now we will record the process for future viewing and share it with you. For more information, seeHttp://www.czvc.com/view.asp? Id = 334This is a pretty good website. This article is not completely copied and corrected the errors in the compilation process, I also highlighted other materials I have seen and the problems mentioned above. This is also an easy mistake I made when I was a beginner.

The window contains a frame and five windows, including left, right, zoom, control, and info. The basic classes of window left, right, and zoom are both cview. Both window control and window info windows are derived from cformview.
To implement the preceding functions, use Appwizard to generate a single document application.ProgramAnd customize the generated default view class as czoomview. Next, follow these steps to create another four windows:

1. Use classwizard to create a new class cfixedsplitter for the application. The base class is cmdichildwnd, then replace all cmdichildwnd with csplitterwnd in this class (because classwizard does not support directly deriving subclasses from the csplitterwnd class );
The constructor and destructor in the new class cfixedsplitter derived from javasichildwnd are both protected members and should be changed to public in the header file. Otherwise, errors will occur during cmainframe construction.
2. Declare the variable for splitting the view in the cmainframe class:
Cfixedsplitter splitterh1; file: // Horizontal Split Window 1
Cfixedsplitter splitterh2; file: // horizontal split window 2
Cfixedsplitter splitterv; file: // Vertical Split Window

3. Use classwizard to add four new classes for the application. cleftview and crightview are derived from the cview class, And ccontrolview and cinfoview are derived from the cformview class; use the resource manager to specify the corresponding dialog box resources for the two cformview classes. Be sure to set the style (attribute) of the two dialogs to ws_child = on, ws_border = off, ws_visible = OFF, ws_caption = off, that is, no title, no border, invisible sub-Windows. If this work is not done, although it can pass during compilation, however, assert errors may occur during running;

4. Add it to the oncreateclient function of the cmainframe classCode, Create a split view

Bool cmainframe: oncreateclient (lpcreatestruct lpcs, ccreatecontext * pcontext)
{
// Todo: add your specialized code here and/or call the base class
Bool RTN = splitterv. createstatic (this,); // split the window client into one row and two columns;
// Split the left client area into three rows and one column, and use the left window separated from the preceding area as the parent window;
Splitterh1.createstatic (& splitterv, 3, 1, ws_child | ws_visible | ws_border, splitterv. idfromrowcol (0, 0 ));
// Divide the right customer area into two rows and one column, and use the right window separated from the preceding area as the parent window;
Splitterh2.createstatic (& splitterv, 2, 1, ws_child | ws_visible | ws_border, splitterv. idfromrowcol (0, 1 ));
// Create a view and call the runtime_class Runtime Library to specify the management class of each view
Splitterh1.createview (0, 0, runtime_class (cleftview), csize (0, 0), pcontext );
Splitterh1.createview (1, 0, runtime_class (crightview), csize (0, 0), pcontext );
Splitterh1.createview (2, 0, runtime_class (ccontrolview), csize (0, 0), pcontext );
Splitterh2.createview (0, 0, runtime_class (czoomview), csize (0, 0), pcontext );
// Add # include "zoomdoc. H" to zoomview. H. Otherwise, the error czoomdoc * cannot be found.

Splitterh2.createview (1, 0, runtime_class (cinfoview), csize (0, 0), pcontext );
// Set the initial position of the horizontal and vertical split bars
Splitterv. setcolumninfo (0,300, 0 );
Splitterh1.setrowinfo( 0,150, 0 );
Splitterh1.setrowinfo( 1,150, 0 );
Splitterh2.setrowinfo (0,200, 0 );
Return RTN ;}

After compilation and running, the program interface will basically look like this. However, when the mouse moves to the split position, the shape of the mouse changes, showing the drag icon, when you press the left mouse button and drag operation, the position of the split bar changes as the mouse moves. If the program needs to prohibit the movement of split entries, You need to continue with the following operations:

In the cfixedsplittewnd class, reload the following functions to prevent mouse dragging and cursor changes:

Void cfixedsplitterwnd: onlbuttondown (uint nflags, cpoint point)
{
Cwnd: onlbuttondown (nflags, point); // the function that is modified to cwnd.
}

Bool cfixedsplitterwnd: onsetcursor (cwnd * pwnd, uint nhittest, uint message)
{
Return cwnd: onsetcursor (pwnd, nhittest, message );
}

Void cfixedsplitterwnd: onmousemove (uint nflags, cpoint point)
{
Cwnd: onmousemove (nflags, point );
}

Next, you can manage your own views as in the Multi-document overlapping window. Each view can display their respective document content separately, which is very convenient. This program can be debugged in the Visual C ++ 6.0 environment in Windows XP

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.