Create a dialog box Color toolbar

Source: Internet
Author: User

It took me half a day to paste the source code.

// CPersonSetDlg Message Processing Program

BOOL CPersonSetDlg: OnInitDialog ()
{
CDialog: OnInitDialog ();

// TODO: add additional initialization here
 
M_toolbar.CreateEx (this, TBSTYLE_FLAT,
WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | CCS_NODIVIDER );
 
M_toolbar.LoadToolBar (IDR_TOOLBAR1 );
HICON m_icon;
M_imagelist.Create (32, 31, ILC_COLOR32 | ILC_MASK, 9, 9 );
M_imagelist.SetBkColor (: GetSysColor (COLOR_BTNFACE ));
M_icon = AfxGetApp ()-> LoadIcon (IDI_ICON1 );
M_imagelist.Add (m_icon );
M_icon = AfxGetApp ()-> LoadIcon (IDI_ICON2 );
M_imagelist.Add (m_icon );
M_icon = afxgetapp ()-> loadicon (idi_icon3 );
M_imagelist.add (m_icon );
M_icon = afxgetapp ()-> loadicon (idi_icon4 );
M_imagelist.add (m_icon );
M_icon = afxgetapp ()-> loadicon (idi_icon5 );
M_imagelist.add (m_icon );
M_icon = afxgetapp ()-> loadicon (idi_icon6 );
M_imagelist.add (m_icon );
M_icon = afxgetapp ()-> loadicon (idi_icon7 );
M_imagelist.add (m_icon );
M_icon = afxgetapp ()-> loadicon (idi_icon8 );
M_imagelist.add (m_icon );
M_icon = afxgetapp ()-> loadicon (idi_icon9 );
M_imagelist.add (m_icon );

Ctoolbarctrl * m_toolbarctrl = & (m_toolbar.gettoolbarctrl ());
M_toolbarctrl-> sethotimagelist (& m_imagelist );
M_toolbarctrl-> SetImageList (& m_imagelist );
M_imagelist.Detach ();

 
// Change attributes
M_toolbar.ModifyStyle (0, TBSTYLE_FLAT | CBRS_TOOLTIPS | TBSTYLE_TRANSPARENT | TBBS_CHECKBOX );
M_toolbar.SetButtons (NULL, 40 );
// Set up each toolbar button to set text
M_toolbar.SetButtonInfo (0, ID1, TBSTYLE_BUTTON, 1 );
M_toolbar.SetButtonText (0, "write ");
M_toolbar.SetButtonInfo (1, ID2, TBSTYLE_BUTTON, 2 );
M_toolbar.SetButtonText (1, "write ");
M_toolbar.SetButtonInfo (2, ID3, TBSTYLE_BUTTON, 3 );
M_toolbar.SetButtonText (2, "write ");
M_toolbar.SetButtonInfo (3, ID4, TBSTYLE_BUTTON, 4 );
M_toolbar.SetButtonText (3, "write ");
M_toolbar.SetButtonInfo (4, ID5, TBSTYLE_BUTTON, 5 );
M_toolbar.SetButtonText (4, "write ");
M_toolbar.SetButtonInfo (5, ID6, TBSTYLE_BUTTON, 6 );
M_toolbar.SetButtonText (5, "write ");
M_toolbar.SetButtonInfo (6, ID7, TBSTYLE_BUTTON, 7 );
M_toolbar.SetButtonText (6, "write ");
M_toolbar.SetButtonInfo (7, ID8, TBSTYLE_BUTTON, 8 );
M_toolbar.SetButtonText (7, "write ");
M_toolbar.SetButtonInfo (8, ID9, TBSTYLE_BUTTON, 9 );
M_toolbar.SetButtonText (8, "write ");
CRect rectToolBar;
// Get the button size
M_toolbar.GetItemRect (0, & rectToolBar );
// Set the button size
M_toolbar.SetSizes (rectToolBar. Size (), CSize (32, 31 ));
 
If (! M_wndReBar.Create (this ))
{
Return-1;
}
M_wndReBar.AddBar (& m_toolbar );

REBARBANDINFO rbbi;
Rbbi. cbSize = sizeof (rbbi); // required
Rbbi. fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE | RBBIM_BACKGROUND;
// Width of the toolbar
Rbbi. cxMinChild = rectToolBar. Width ();
// Height
Rbbi. cyMinChild = rectToolBar. Height ();
// The following line of code adds a background bitmap to the toolbar. Note the RBBIM_BACKGROUND flag in rbbi. fMask.
Rbbi. hbmBack = LoadBitmap (: AfxGetInstanceHandle (), MAKEINTRESOURCE (IDB_TOOLBARBKMAP ));
 
Rbbi. cx = rbbi. cxIdeal = rectToolBar. Width () * 10;
 
M_wndReBar.GetReBarCtrl (). SetBandInfo (0, & rbbi );
M_toolbar.MoveWindow (CRect (480,-1,870,500 ));
 
Return true; // return true unless you set the focus to a control
// Exception: the OCX attribute page should return false.
}

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.