Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC Toolbar icon
Hi all,
 
I wanna make a large toolbar with support of icons with more colors depth than default in Visual Studio.
 
I am using Visual Studio 2005. So people, hwo can I create a toolbar with support of 256 colors (for instance).
 
NB: my toolbar is on a CDialog Window.
 
I used the Code found : here but did not work.
 
int CSalariesForm::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;
 
    HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
        MAKEINTRESOURCE(IDR_MAINFRAME1), IMAGE_BITMAP,
        0,0, LR_CREATEDIBSECTION | LR_LOADMAP3DCOLORS);
 
    CBitmap bm;
    bm.Attach(hBitmap);
 

    CImageList m_imagelist;
    m_imagelist.Create(20, 20, ILC_COLOR8, 4, 4);
    m_imagelist.Add(&bm, (CBitmap*) NULL);
 
    cToolBar.Create(this);
    cToolBar.GetToolBarCtrl().SetImageList(&m_imagelist);
 
    cToolBar.ShowWindow(SW_SHOW);
    cToolBar.SetBarStyle(CBRS_TOOLTIPS | CBRS_FLOATING | CBRS_ALIGN_TOP | CBRS_FLYBY);
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
    return 0;
}
 
Help !!!
 
Thank you
Posted 23-Dec-12 5:28am
Edited 24-Dec-12 10:37am
v2
Comments
Schehaider_Aymen at 24-Dec-12 14:30pm
   
Up !!!

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I found the answer, so this is how I proceeded :
 
//header file
private:
    CImageList m_imagelist;
    CToolBar   m_toolbar;
&
// source file
enum { width = 20, height = 20 }; // width and height of one button image

m_toolbar.Create(this);
 
// create the image list
m_imagelist.Attach(
    ImageList_LoadImage(
        AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1), width, 4, 
        CLR_DEFAULT, IMAGE_BITMAP, LR_CREATEDIBSECTION | LR_LOADTRANSPARENT )
);
 
// set button and image sizes (copied from CToolBar::LoadToolBar)
m_toolbar.SetSizes(CSize(width+7,height+7), CSize(width,height));
 
// set image list
m_toolbar.GetToolBarCtrl().SetImageList(&m_imagelist);
 
// define command ids for each button
const UINT cmdIds[] = { 
    IDOK,
    0,        // separator
    IDCANCEL,
};
 
// assign ids to the toolbar
m_toolbar.SetButtons(cmdIds, sizeof(cmdIds)/sizeof(UINT));
 
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100