Easy interface of the class VC: Wenling, Zhejiang Province Wang Jun bureau
The figure below is a interface similar to the VC, left, bottom under the bottom of which can float, variable size control window. Many friends want to implement similar interfaces in their own programs, because this type of interface is very wide, very versatility, so the author summarizes the steps of implementation, and provides source code for everyone to refer! Download this article Example Project 44.3K (Latest Update: February 8, 2004) 1. The implementation class of two windows in the realization schematic is derived from CControlbar. We don't need to implement such a class from head until tail, because Cristi Posea Mr. has achieved a class called CSIZINGCONTROLBAR for us, and it is quite perfect! What we have to do is take advantage of this class, in order to make it as simple as possible, the author modifies the CSIZINGCONTROLBAR class and named ccoolbar. Next we will detail how to use this class to implement the interface we need. 2. Implementation Step Example [1] Prepared to create a new MFC project called Bardemo, the SDI interface, and other options default. The four files in the sample code in this example code are copied to the project directory. In the menu project-> add to project-> files, add four files to the project, and a class called CCOOLBAR will appear in the ClassView. In the stdafx.h file, add #include "sizecbar.h" #include "scbarg.h" [2] to start encoding 2.1 to add member variables for CMAINFRAME CCoolbar M_Wndmybar1; /// We use the window to the left
CCOOLBAR M_WNDMYBAR2; // / Dock the following code needs to be added to CMAINFRAME :: OnCreate, the method is not very different from the creation of the normal toolbar! 2. Create ControlBar if (! M_wndmybar1.create "(" My Control strip "), 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 M_Wndmybar1.setBarsTyle (M_Wndmybar1.GetBarsTyle () | CBRS_ToolTIPS |
CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
M_Wndmybar2.setbarstyle (m_wndmybar2.getbarstyle () | CBRS_Tooltips |
CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
M_Wndmybar1.enableDocking (CBRS_ALIGN_ANY);
M_Wndmybar2.enableDocking (CBRS_ALIGN_ANY);
DockControlbar (& M_Wndmybar1, AFX_IDW_DOCKBAR_LEFT); // Stop on the left
DockControlbar (& M_Wndmybar2, AFX_IDW_DOCKBAR_BOTTOM); /// Stop in the right at this time we have generated two control bar window, but there is no thing in the window! Let us do the last thing: add the required parts to the window! 2.4 Adding My Control This problem seems to be a bit of trouble. It is quite simple: we use the control bar window pointer as the parent window pointer to these controls when creating these controls! Please see the following example (you need to pay attention to the following forms, you can only select one, and add multiple sub-windows to a control bar window will result in failure!) (1) put the editor control into the following control strip Add member variables in the CMAINFRAME class to CEDIT M_Wndedit; create editing control M_WndIt.create (WS_VSCROLL | WS_CHILD | WS_VSIBLE | ES_AUTOVSCROLL |
ES_MULTILINE | ES_WANTRETURN, CRECT (0, 0, 0, 0), & M_Wndmybar2, 101);
M_Wndedit.ModifyStyleex (0, WS_EX_CLIENTEDGE);
(2) Put the tree control in the left side of the control strip window to add member variables in the CMAINFRAME class CTREECTRL M_WNDTREE ;; Create a tree control after creating Controlbar
/ This section creates a tree control
IF (! m_wndtree.create (ws_child | ws_visible |
TVS_haslines | TVS_HASBUTTONS | TVS_LINESTROOT,
CRECT (0, 0, 0, 0), & M_Wndmybar1, 100)))
{
Trace0 ("Failed to Create Instant Bar Child / N");
Return -1;
}
M_Wndtree.ModifyStyleex (0, WS_EX_CLIENTEDGE);
Add content to tree controls ///
HtreeItem hti = m_wndtree.insertitem (_T ("VC Knowledge Base Online Magazine)));
M_Wndtree.InsertItem (_T ("electronic document"));
M_Wndtree.InsertItem (_T ("Online Magazine"), HTI);
m_wndtree.insertitem ("Online Magazine Second"), HTI); (3) Put the dialog box in the control bar first created a child-free Border dialog box in the resource editor, ID is IDD_DIALOGBAR, and Generate a CVCKBASEDLG class as a template and add member variables in CMAINFRAME CVCKBASEDLG M_WNDVCKBASE; and then create a dialog m_wndvckbase.create (IDD_DIALOGBAR, & M_WNDMYBAR1) using the following code after creating the Controlbar;
m_wndvckbase.showwindow (sw_show); (4) Provide a package class called CCoolTabCtrl in the sample code of TabCtrl into the left control strip, we can simply create TabCtrl, first see the following code m_tabctrl. Create (TCS_DOWN | WS_CHILD | WS_VISIBLE, CRECT (0, 0, 100, 100), & M_WndmyBar1, 125;
/ This section creates a tree control
IF (! m_wndtree.create (ws_child | ws_visible |
TVS_haslines | TVS_HASBUTTONS | TVS_LINESTROOT,
CRECT (0, 0, 0, 0), & M_Tabctrl, 100)) /// Note, here is the parent window of m_tabctrl as M_Wndtree
{
Trace0 ("Failed to Create Instant Bar Child / N");
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 ("electronic document"));
M_Wndtree.InsertItem (_T ("Online Magazine"), HTI);
M_Wndtree.Insertitem (_T ("The second phase of online magazine"), HTI);
/// Add the tree control into TabCtrl
m_tabctrl.addpage (& M_Wndtree, "VC Knowledge Base", IDi_ICON1); // Add Tree Control to the first page
m_tabctrl.addpage (runtime_class (cvckbasedlg), IDD_Dialogbar, "second page", IDi_icon2); /// Add the CVCKBASEDLG dialog to the second page
m_tabctrl.addpage (runtime_class (cmydlg), Idd_Dialogbar2, "Page 3", IDi_ICON3); // Add the CMYDLG dialog to the third page
m_tabctrl.UpdateWindow (); /// Update TabControl Need to note that you want to add a dialog box in TabControl, you must add the following information in its class definition, class implementation files: For example, a CVCKBasedlg class, add declare_dynce to vckbasedlg.h ( CVCKBasedlg) Class Cvckbasedlg: Public CDialog
{
// construction
PUBLIC:
Cvckbasedlg (CWND * PParent = null); // Standard Constructionor
Declare_Dyncreate (cvckbasedlg) Increase import_dyncreate (cdckbasedlg, cdialog) in .cpp, we have already met! We can compile running to see if the two controls have created success. Cool! Only use this line of code to realize the interface of dreams! Third, more advanced topics 3.1 This controlbar disappears at the top of the top, turned into a normal ToolWindow type title bar. In order to avoid this, we need to add: #ifdef _scb_replace_miniframe after EnableDocking () in CMAINFRAME :: OnCreate ()
m_pfloatingframeclass = runtime_class (cscbminidockframeWnd);
#ENDIF / / _ SCB_REPLACE_MINIFRAME
And plus #define _scb_replace_miniframe in stdafx.h
3.2 Different styles of this class can be added to STDAFX.H, you may wish to try! 3.3 How to stop two ControlBar in the same row DockControlbar (& m_Wndmybar1, AFX_IDW_DOCKBAR_BOTTOM); // Stop at the bottom
RECALCLAYOUT ();
CRECT RECT;
M_Wndmybar1.GetWindowRect (Rect);
Rect.offsetRect (1, 0); // Offset one position
DockControlbar (& M_Wndmybar2, AFX_IDW_DOCKBAR_BOTTOM, REC); /// also stops at the bottom 3.4 How to stop two ControlBar in the same column DockControlbar (& m_Wndmybar1, AFX_IDW_DOCKBAR_RIGHT); // Stop on the right
RECALCLAYOUT ();
CRECT RECT;
M_Wndmybar1.GetWindowRect (Rect);
Rect.offsetRect (0, 1); // Did you see the difference here?
DockControlbar (& M_Wndmybar2, AFX_IDW_DOCKBAR_RIGHT, RECT); // / also docked in the right
After that, the paper is in a hurry, and the mistakes hope that everyone is correct! Finally, let us thank Mr. Cristi Posea to provide us with such a good CSIZINGCONTROLBAR!