Add a 24-color rebar code snippet

Source: Internet
Author: User

Int cmainframe: createrebar ()
{
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; // fail to create
}

// Attach the hicolor bitmaps to the toolbar
Attachtoolbarimages (idb_hicolor_toolbar,
Idb_hicolor_toolbar_disabled,
Idb_hicolor_toolbar_hot );
Return 0;
}
// Find every pixel of the default background color in the specified
// Bitmap and set each one to the user's button color.
Static void replacebackgroundcolor (cbitmap & iobm)
{
// Figure out how many pixels there are in the bitmap
Bitmap bminfo;

Verify (iobm. getbitmap (& bminfo ));
 
// Add support for additional bit depths here if you choose
Verify (bminfo. bmbitspixel = 24 );
Verify (bminfo. bmwidthbytes = (bminfo. bmwidth * 3 ));

Const uint numpixels (bminfo. bmheight * bminfo. bmwidth );

// Get a pointer to the pixels
Dibsection Ds;

Verify (iobm. GetObject (sizeof (dibsection), & Ds) = sizeof (dibsection ));

Rgbtriple * pixels = reinterpret_cast <rgbtriple *> (Ds. dsbm. bmbits );
Verify (pixels! = NULL );

// Get the user's preferred button color from the system
Const colorref buttoncolor (: getsyscolor (color_btnface ));
Const rgbtriple userbackgroundcolor = {
Getbvalue (buttoncolor), getgvalue (buttoncolor), getrvalue (buttoncolor )};

// Search through the pixels, substituting the user's button
// Color for any pixel that has the magic background color
For (uint I = 0; I <numpixels; ++ I)
{
If (pixels [I]. rgbtblue = kbackgroundcolor. rgbtblue &&
Pixels [I]. rgbtgreen = kbackgroundcolor. rgbtgreen &&
Pixels [I]. rgbtred = kbackgroundcolor. rgbtred)
{
Pixels [I] = userbackgroundcolor;
}
}
}

// Create an image list for the specified BMP Resource
Static void maketoolbarimagelist (uint inbitmapid,
Cimagelist & outimagelist)
{
Cbitmap bm;

// If we use cbitmap: loadbitmap () to load the bitmap, the colors
// Will be forced CED to the bit depth of the main screen and we won't
// Be able to access the pixels directly. To avoid those problems,
// We'll load the bitmap as a dibsection instead and attach
// Dibsection to the cbitmap.
Verify (BM. Attach (: LoadImage (: afxfindresourcehandle (
Makeintresource (inbitmapid), rt_bitmap ),
Makeintresource (inbitmapid), image_bitmap, 0, 0,
(Lr_defaultsize | lr_createdibsection ))));

// Replace the specified color in the bitmap with the user's
// Button color
: Replacebackgroundcolor (BM );

// Create a 24 bit image list with the same dimensions and number
// Of buttons as the toolbar
Verify (outimagelist. Create (
Kimagewidth, kimageheight, ktoolbarbitdepth, knumimages, 0 ));

// Attach the bitmap to the image list
Verify (outimagelist. Add (& BM, RGB (0, 0, 0 ))! =-1 );
}

// Load the high Color toolbar images and attach them to m_wndtoolbar
Void cmainframe: attachtoolbarimages (uint innormalimageid,
Uint indisabledimageid,
Uint inhotimageid)
{
// Make high-color image lists for each of the bitmaps
: Maketoolbarimagelist (innormalimageid, m_toolbarimages );
: Maketoolbarimagelist (indisabledimageid, m_toolbarimagesdisabled );
: Maketoolbarimagelist (inhotimageid, m_toolbarimageshot );

// Get the Toolbar Control associated with the ctoolbar object
Ctoolbarctrl & barctrl = m_wndtoolbar.gettoolbarctrl ();

// Attach the image lists to the Toolbar Control
Barctrl. setimagelist (& m_toolbarimages );
Barctrl. setdisabledimagelist (& m_toolbarimagesdisabled );
Barctrl. sethotimagelist (& m_toolbarimageshot );
}

Void cmainframe: oncreaterebar ()
{
If (0> createrebar () return;

M_wndtoolbar.enabledocking (cbrs_align_any );
Enabledocking (cbrs_align_any );
Dockcontrolbar (& m_wndtoolbar );
}

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.