You can edit the .rc file manually to add a custom toolbar resource and a 15/16/24/32-bit bitmap. Any version of Visual Studio will display this toolbar resource in the resource tree but you will not be able to edit it in the resource editor because the editor does not support 15/16/24/32-bit toolbars. So, please simply insert the bitmap resource and define command identifiers for all the images in this bitmap in your resource.h file manually at this first step. The next step is to initialize the command manager with the images stored in your bitmap using the following code:
#define __COUNT_OF_IMAGES__ . . . // put here the real number of images in your bitmap
static UINT g_arrCommandIDs[ __COUNT_OF_IMAGES__ ] =
{
ID_COMMAND_0, // define these commands in your resource.h file
ID_COMMAND_1,
ID_COMMAND_2,
// . . .
};
CSize _sizeOneImage( 44, 40 );
CRect _rcCurrentImage( 0, 0, _sizeOneImage.cx, _sizeOneImage.cy );
COLORREF clrTransparent = . . .; // color of transparent pixels or COLORREF(-1L) vale for 32-bit images with alpha channel
CExtBitmap _bmp;
VERIFY( _bmp.LoadBMP_Resource( MAKEINTRESOURCE( IDR_YOUR_BITMAP ) ) );
for( int i = 0; i < __COUNT_OF_IMAGES__; i ++ )
{
CExtCmdItem * pCmdItem =
g_CmdManager->CmdAllocPtr( “your command profile name”, g_arrCommandIDs[ i ] );
ASSERT( pCmdItem != NULL );
pCmdItem;
VERIFY(
CmdSetIcon(
“your command profile name”,
g_arrCommandIDs[ i ],
bmp,
clrTransparent,
&_rcCurrentImage
)
);
_rcCurrentImage.OffsetRect( _sizeOneImage.cx, 0 );
}
Now you can use your images in the toolbar. The following code does the same as the CExtToolControlBar::LoadToolBar() method does:
// this array contains identifiers from the g_arrCommandIDs and
// the ID_SEPARATOR values in the locations where separators should appear
static UINT g_arrToolbarButtonIDs[] =
{
ID_COMMAND_0,
ID_COMMAND_1,
ID_SEPARATOR, // separator
ID_COMMAND_2,
// . . .
};
m_wndToolBar.SetButtons(
sizeof(g_arrToolbarButtonIDs) / sizeof(g_arrToolbarButtonIDs[0])
);
m_wndToolBar.InitContentExpandButton(); // creates chevron button