Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.

C++
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
Updated 24-Dec-12 9:37am
v2
Comments
Schehaider_Aymen 24-Dec-12 14:30pm    
Up !!!

1 solution

I found the answer, so this is how I proceeded :

C++
//header file
private:
    CImageList m_imagelist;
    CToolBar   m_toolbar;

&
C++
// 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);
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900