MFC Tools Bar

Source: Internet
Author: User

CToolBar m_wndToolBar;

CToolBar M_wndtestbar;
CComboBoxEx M_oedit;
CToolBar M_wndgotobar;

CReBar M_orebar;


CStatusBar M_wndstatusbar;
CChildView M_wndview;

CToolBar m_wndtesttoolbar1;
CToolBar m_wndtesttoolbar2;
CToolBar M_wndtesttoolbar3;

CReBar M_wndgroup;
int CMainFrame::OnCreate (lpcreatestruct lpcreatestruct)
{
EnableDocking (Cbrs_align_any);
if (cframewnd::oncreate (lpcreatestruct) = =-1)
return-1;

Create a view to occupy the frame's workspace
if (!m_wndview.create (null, NULL, Afx_ws_default_view, CRect (0, 0, 0, 0), this, Afx_idw_pane_first, NULL))
{
TRACE0 ("Failed to create view window \ n");
return-1;
}

if (!m_wndtoolbar.createex (this, Tbstyle_flat, Ws_child | ws_visible | Cbrs_top | Cbrs_gripper | Cbrs_tooltips | cbrs_flyby | Cbrs_size_dynamic) | |
!m_wndtoolbar.loadtoolbar (IDR_MAINFRAME))
{
TRACE0 ("Failed to create toolbar \ n");
return-1; Failed to create
}

if (!m_wndstatusbar.create (this))
{
TRACE0 ("Failed to create status bar \ n");
return-1; Failed to create
}

Https://www.xuebuyuan.com/647176.html
1. Creating a Toolbar Object
M_wndtestbar.createex (this);
M_wndgotobar.createex (this);

To set a picture for a toolbar:
Idb_bmp_toolbar is the image resource ID,
22 indicates the width of each picture cell, cimagelist the image by this width
#ff00ff表示图片的背景掩码色
/*cimagelist img;
Img. Create (idr_mainframe, 0, #ffffff);
M_wndtestbar.gettoolbarctrl (). SetImageList (&IMG);
Img. Detach (); */

Set the picture and text of the three buttons on a toolbar
M_wndtestbar.setbuttons (NULL, 3);
M_wndtestbar.setbuttoninfo (0, Id_1, Tbstyle_button,-1);
M_wndtestbar.setbuttontext (0, L "1");
M_wndtestbar.setbuttoninfo (1, Id_2, Tbstyle_button, 1);
M_wndtestbar.setbuttontext (1, L "2");
M_wndtestbar.setbuttoninfo (2, Id_3, Tbstyle_button, 2);
M_wndtestbar.setbuttontext (2, L "3");

M_wndgotobar.setbuttons (NULL, 2);
M_wndgotobar.setbuttoninfo (0, Id_4, Tbstyle_button, 3);
M_wndgotobar.setbuttontext (0, L "4");
M_wndgotobar.setbuttoninfo (1, Id_5, Tbstyle_button, 4);
M_wndgotobar.setbuttontext (1, L "5");


To set the properties of a toolbar
M_wndtestbar.setbarstyle (M_wndtestbar.getbarstyle () |
Cbrs_tooltips | CBRS_FLYBY);
M_wndgotobar.setbarstyle (M_wndtestbar.getbarstyle () |
Cbrs_tooltips | CBRS_FLYBY);
2. Create an edit box object
M_oedit.create (Ws_child | Ws_visible, CRect (0, 0, +), this, 0);

3. Create a CReBar object
M_orebar.create (this);

4. Bind toolbars and edit boxes to CReBar
M_orebar.addbar (&m_wndtestbar, NULL, NULL, Rbbs_nogripper |    Rbbs_fixedbmp); //  | Rbbs_usechevron | Rbbs_childedge
M_orebar.addbar (&m_wndgotobar, NULL, NULL, Rbbs_nogripper |    Rbbs_fixedbmp); //  | Rbbs_usechevron
M_orebar.addbar (&m_oedit, NULL, NULL, rbbs_nogripper);
M_orebar.setbarstyle (M_orebar.getbarstyle () | cbrs_size_fixed);
M_orebar.setbarstyle (M_orebar.getbarstyle ());


5. To set the properties of a toolbar in CReBar
CRect Recttoolbar;
M_wndtestbar.gettoolbarctrl (). GetWindowRect (&recttoolbar);
CRect Recttoolbaritem;
M_wndtestbar.getitemrect (0, &recttoolbaritem);
Rebarbandinfo Rbbi;
rbbi.cbsize = sizeof (Rbbi);
Https://docs.microsoft.com/zh-cn/windows/desktop/api/commctrl/ns-commctrl-tagrebarbandinfoa
Rbbi.fmask = Rbbim_childsize | Rbbim_idealsize | Rbbim_size | rbbim_id;
Rbbi.cxminchild = Recttoolbaritem.width ();
Rbbi.cyminchild = Recttoolbaritem.height ();
rbbi.cx = Rbbi.cxideal = Recttoolbar.width () * 1;
Rbbi.wid = 0;
M_orebar.getrebarctrl (). SetBandInfo (0, &rbbi);
Rbbi.wid = 0;
M_orebar.getrebarctrl (). SetBandInfo (2, &rbbi);

Finally, show the toolbar.
M_orebar.setwindowpos (NULL, 0, 0, 260, Swp_showwindow);

M_wndgotobar.gettoolbarctrl (). Hidebutton (Id_5, TRUE);
M_wndgotobar.gettoolbarctrl (). Hidebutton (Id_5, FALSE);

return 0;
}

int CMainFrame::D otoolbar ()
{
//////////////////////////////////////////////////////////////////////////////////////////////////////////
Https://www.xuebuyuan.com/zh-tw/1919985.html
M_wndtoolbar.setheight (100);
M_wndstatusbar.setindicators (indicators, sizeof (indicators)/sizeof (UINT));

if (!m_wndtesttoolbar1.create (This, ws_child | ws_visible | Cbrs_top | cbrs_size_fixed))
{
TRACE0 ("Failed to create status bar \ n");
return-1;
}
if (!m_wndtesttoolbar2.create (This, ws_child | ws_visible | Cbrs_top | cbrs_size_fixed))
{
TRACE0 ("Failed to create status bar \ n");
return-1;
}
if (!m_wndtesttoolbar3.create (This, ws_child | ws_visible | Cbrs_top | cbrs_size_fixed))
{
TRACE0 ("Failed to create status bar \ n");
return-1;
}



if (!m_wndgroup.create (this, rbs_fixedorder) | | |!m_wndgroup.addbar (&M_WNDTESTTOOLBAR1, NULL, NULL, NULL, RBBS_ Fixedbmp | Rbbs_nogripper)
|| !m_wndgroup.addbar (&M_WNDTESTTOOLBAR2, NULL, NULL, NULL, rbbs_fixedbmp)
|| !m_wndgroup.addbar (&M_WNDTESTTOOLBAR3, NULL, NULL, NULL, rbbs_fixedbmp))
{
TRACE0 ("Failed to create status bar \ n");
return-1;
}

int iCount = M_wndgroup.getrebarctrl (). Getbandcount ();


M_wndtesttoolbar1.setheight (100);
M_wndtesttoolbar2.setheight (100);
M_wndtesttoolbar3.setheight (100);

M_wndtesttoolbar3.gettoolbarctrl ();
int iheight = M_wndgroup.getrebarctrl (). Getbarheight ();

M_wndtesttoolbar1.setbuttons (Uitestids, 1);
M_wndtesttoolbar1.setbuttoninfo (0, Testbtnid, Tbstyle_button, 0);
M_wndtesttoolbar1.setbuttontext (0, L "dfscvbncxcvncvbndf");


Get button State GetState
M_wndtesttoolbar1.gettoolbarctrl (). SetState (0, Tbstate_hidden);

Hide button
M_wndtesttoolbar1.gettoolbarctrl (). Hidebutton (Testbtnid, TRUE);
M_wndtesttoolbar1.gettoolbarctrl (). Enablebutton (Testbtnid, TRUE);

DockControlBar (&m_wndtesttoolbar1, afx_idw_dockbar_top);

/*m_wndtoolbar.enabledocking (Cbrs_align_any);
EnableDocking (Cbrs_align_any);
DockControlBar (&m_wndtoolbar); * *

Height width of belt
https://bbs.csdn.net/topics/390397805
Change some properties
Rebarbandinfo Rbbi;
rbbi.cbsize = sizeof (REBARBANDINFO); This is a must-fill
Rbbi.fmask = Rbbim_childsize | Rbbim_idealsize | rbbim_size;//| Rbbim_background;
Width of the tool bar
Rbbi.cxminchild = Recttoolbar.width ();
Rbbi.cxminchild = 100;
Height
Rbbi.cyminchild = Recttoolbar.height ();
Rbbi.cyminchild = 32;

The following line of code is to add a background bitmap to the toolbar, notice the RBBIM_BACKGROUND flag on the Rbbi.fmask
Rbbi.hbmback = LoadBitmap (:: AfxGetInstanceHandle (), Makeintresource (Idb_toolbarbkmap));

rbbi.cx = Rbbi.cxideal = 30;

M_wndgroup.getrebarctrl (). SetBandInfo (0, &rbbi);
Rbbi.cxminchild = 100; Width of the tool bar
M_wndgroup.getrebarctrl (). SetBandInfo (1, &rbbi);
Rbbi.cxminchild = 1000; Width of the tool bar
M_wndgroup.getrebarctrl (). SetBandInfo (2, &rbbi);
}

BOOL CMainFrame::P Recreatewindow (createstruct& CS)
{
if (! CFrameWnd::P Recreatewindow (CS))
return FALSE;
TODO: here by modifying
CREATESTRUCT CS To modify a window class or style

Cs.dwexstyle &= ~ws_ex_clientedge;
Cs.lpszclass = AfxRegisterWndClass (0);
return TRUE;
}

MFC Tools Bar

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.