Click here to Skip to main content
Sign Up to vote bad
good
See more: MFCToolbaricon
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 - 4:28
Edited 24 Dec '12 - 9:37

Comments
Schehaider_Aymen - 24 Dec '12 - 14:30
Up !!!

1 solution

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  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 586
1 Maciej Los 255
2 Slacker007 240
3 Aarti Meswania 233
4 OriginalGriff 230
0 Sergey Alexandrovich Kryukov 9,118
1 OriginalGriff 7,134
2 CPallini 3,803
3 Rohan Leuva 3,135
4 Maciej Los 2,558


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