Easy Implementation of the class VC interface (dock window)

Source: Internet
Author: User
Author: Wang Jun, Wenling Telecom Bureau, Zhejiang Province

I. Implementation Principle
The implementation classes of the two windows in the figure are derived from the ccontrolbar, and we do not need to implement the class from the beginning to the end, because Mr. Cristi posea has already implemented a class called csizingcontrolbar for us and has done quite well! All we need to do is make good use of this class. To make it as concise as possible, I modified the csizingcontrolbar class and named it ccoolbar. Next we will introduce in detail how to use this class to implement the interface we need.

Ii. Example of implementation steps
[1] preparations
Create an MFC project named bardemo, SDI interface, and other options are default.
Copy the sizecbar. h sizecbar. cpp scbarg. h scbarg. cpp files in the sample code in this article to the project directory.
In the menu project-> Add to project-> files, add four files to the project. A class called ccoolbar is displayed in classview.
Add to stdafx. h file
# Include "sizecbar. H"
# Include "scbarg. H"

[2] Start Encoding

2.1 Add member variables for cmainframe

Ccoolbar m_wndmybar1; // we use it as the left-side window ccoolbar m_wndmybar2; // the window that is docked below

The following code needs to be added to cmainframe: oncreate. There is no big difference between the method and the normal toolbar creation!

2.2 create a controlbar

If (! M_wndmybar1.create (_ T ("My control bar"), this, 123) {trace0 ("failed to create mybar \ n"); Return-1;} If (! M_wndmybar2.create (_ T ("My control bar 2"), this, csize (100,100), true, 124) {trace0 ("failed to create mybar \ n "); return-1 ;}

2.3 Stop Control

Compute (compute () | cbrs_tooltips | cbrs_flyby | compute); compute (cbrs_align_any ); dockcontrolbar (& m_wndmybar1, afx_idw_dockbar_left); // dock to the left dockcontrolbar (& m_wndmybar2, afx_idw_dockbar_bottom); // dock to the right

Now we have generated two control bar windows, but there is nothing in the window! Let's do the last thing: add the required parts to the window!

2.4 Add my controls

This problem may seem a little complicated. In fact, we only need to assign the control bar window pointer as the parent window pointer to these controls when creating these controls!
Please refer to the following example (note that you can only select one of the following forms. Adding multiple subwindows to a control bar window will cause failure !)
(1) Place the Edit Control in the control bar window below.

Add the member variable cedit m_wndedit to the cmainframe class;
Create the Edit Control m_wndedit.create (ws_vscroll | ws_child | ws_visible | es_autovscroll | es_multiline | es_wantreturn, crect (101,), & m_wndmybar2,) after creating a controlbar );
M_wndedit.modifystyleex (0, ws_ex_clientedge );

(2) Place the tree control in the control bar window on the left.

Add the member variable ctreectrl m_wndtree to the cmainframe class ;;
After creating a controlbar, create a tree control/*** // This Code creates a tree control ////////// //
If (! M_wndtree.create (ws_child | ws_visible |
Tvs_haslines | tvs_hasbuttons | tvs_linesatroot,
Crect (0, 0, 0, 0), & m_wndmybar1, 100 ))
...{
Trace0 ("failed to create instant bar child ");
Return-1;
}
M_wndtree.modifystyleex (0, ws_ex_clientedge );
/** // Add content to the tree control ///
Htreeitem HTI = m_wndtree.insertitem (_ T ("VC Knowledge Base online magazine "));
M_wndtree.insertitem (_ T (" 文 "));
M_wndtree.insertitem (_ T ("online magazine No. 1"), HTI );
M_wndtree.insertitem (_ T ("online magazine Phase II"), HTI );

(3) Add the dialog box to the control bar.
First, create a child-type borderless dialog box in the resource editor. The ID is idd_dialogbar and generate the cvckbasedlg class as a template,
Add the member variable cvckbasedlg m_wndvckbase to the cmainframe. Then, create the controlbar with the following code dialog box:

m_wndVCKBASE.Create(IDD_DIALOGBAR,&m_wndMyBar1);m_wndVCKBASE.ShowWindow(SW_SHOW);

(4) Place tabctrl to the control bar on the left.
The sample code in this article provides an encapsulation class called ccooltabctrl. We can use it to create a tabctrl. See the following code first.

M_tabctrl.create (tcs_down | ws_child | ws_visible, crect (0, 0, 100,100), & m_wndmybar1, 125 );
/** // This Code creates a tree control ////////////
If (! M_wndtree.create (ws_child | ws_visible |
Tvs_haslines | tvs_hasbuttons | tvs_linesatroot,
Crect (0, 0, 0, 0), & m_tabctrl, 100)/** // note that m_tabctrl is used as the parent window of m_wndtree.
...{
Trace0 ("failed to create instant bar child ");
Return-1;
}
M_wndtree.modifystyleex (0, ws_ex_clientedge );
/** // Add content to the tree control
Htreeitem HTI = m_wndtree.insertitem (_ T ("VC Knowledge Base online magazine "));
M_wndtree.insertitem (_ T (" 文 "));
M_wndtree.insertitem (_ T ("online magazine No. 1"), HTI );
M_wndtree.insertitem (_ T ("online magazine Phase II"), HTI );
/** // Add the tree control to tabctrl
M_tabctrl.addpage (& m_wndtree, "VC knowledge base", idi_icon1);/** // Add the tree control to the first page
M_tabctrl.addpage (runtime_class (cvckbasedlg), idd_dialogbar, "page 2", idi_icon2);/** // Add the cvckbasedlg dialog box to page 2
M_tabctrl.addpage (runtime_class (cmydlg), idd_dialogbar2, "Third page", idi_icon3);/** // Add the cmydlg dialog box to the third page

M_tabctrl.updatewindow ();/*** // update tabcontrol

Note that you want to add a dialog box to tabcontrol. In its class definition, the following information must be added to the class implementation file:
For example, in the cvckbasedlg class, add declare_dyncreate (cvckbasedlg) to vckbasedlg. h)

Class cvckbasedlg: Public cdialog
...{
// Construction
Public:
Cvckbasedlg (cwnd * pparent = NULL); // standard Constructor
Declare_dyncreate (cvckbasedlg) added implement_dyncreate (cvckbasedlg, cdialog) to. cpp)

Now we are done! We can compile and run the command to check whether the two control bars have been successfully created.
Wow! With just a few lines of code, you can achieve the interface you dream!

3. More advanced topics
3.1 When the controlbar is floating, the top handle disappears and becomes a normal toolwindow title bar. To avoid this problem, add the following content after enabledocking () in cmainframe: oncreate:

 

3.2 another style of this class can be

# Ifdef _ scb_replace_miniframe
M_pfloatingframeclass = runtime_class (cscbminidockframewnd );
# Endif // _ scb_replace_miniframe
Add # DEFINE _ scb_replace_miniframe to stdafx. h.

Add # DEFINE _ scb_style_flat to stdafx. h to generate it. Try it!

3.3 How to dock two controlbars in the same row

Dockcontrolbar (& m_wndmybar1, afx_idw_dockbar_bottom);/** // dock to the bottom
Recalclayout ();
Crect rect;
M_wndmybar1.getwindowrect (rect );
Rect. offsetrect (1, 0); // offset a position
Dockcontrolbar (& m_wndmybar2, afx_idw_dockbar_bottom, rect);/** // It is also docked at the bottom

3.4 how to dock two controlbars in the same column

Dockcontrolbar (& m_wndmybar1, afx_idw_dockbar_right);/** // dock to the right
Recalclayout ();
Crect rect;
M_wndmybar1.getwindowrect (rect );
Rect. offsetrect (0, 1); // Do you see the difference here?
Dockcontrolbar (& m_wndmybar2, afx_idw_dockbar_right, rect);/** // also dock to the right
Related Article

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.