Click here to Skip to main content
15,920,513 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Bitmaps Pin
Mark Salsbery13-Nov-06 6:00
Mark Salsbery13-Nov-06 6:00 
GeneralRe: Bitmaps Pin
BlitzPackage13-Nov-06 8:14
BlitzPackage13-Nov-06 8:14 
GeneralRe: Bitmaps Pin
Mark Salsbery13-Nov-06 8:29
Mark Salsbery13-Nov-06 8:29 
GeneralRe: Bitmaps Pin
Mark Salsbery13-Nov-06 8:33
Mark Salsbery13-Nov-06 8:33 
GeneralRe: Bitmaps Pin
BlitzPackage13-Nov-06 8:45
BlitzPackage13-Nov-06 8:45 
GeneralRe: Bitmaps Pin
Mark Salsbery13-Nov-06 9:10
Mark Salsbery13-Nov-06 9:10 
GeneralRe: Bitmaps Pin
BlitzPackage13-Nov-06 9:22
BlitzPackage13-Nov-06 9:22 
GeneralRe: Bitmaps Pin
Mark Salsbery13-Nov-06 10:54
Mark Salsbery13-Nov-06 10:54 
Here's an example of a Windows toolbar common control with two buttons...

Add these to your window class:
CToolBarCtrl ToolBar;
CImageList MyImageList;

Add this to your window class' .cpp file
static TBBUTTON ToolBarButtonDescs[] =
{
	{0, ID_BUTTON1, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0} ,
	{1, ID_BUTTON2, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0} //,
};

Add this to the window class constructor
MyImageList.Create(IDB_BITMAP, 18, 18, RGB(0x00,0xFF,0x00));

Add this to the window class' OnCreate() (WM_CREATE handler)
ToolBar.Create(WS_CHILD | WS_VISIBLE, CRect(0,0,100,20), this, ID_TOOLBAR);
ToolBar.SetImageList(&MyImageList);
ToolBar.AddButtons(sizeof(ToolBarButtonDescs) / sizeof(TBBUTTON), ToolBarButtonDescs);

The trick is creating the image list bitmap. In this case I have two buttons, 18 pixels wide so
add a bitmap resource 36x18. I've set the bitmap index for button 1 to index 0 and button 2 to
index 1 in the image list. So the rect (0,0,17,17) in the bitmap needs to be the image you want
on the first button and the rect (18,0,35,17) will be the image for the second button. I've
specified RGB(0x00,0xFF,0x00) (bright green) as the transparent color so draw any areas you want
to be transparent in that color. The image list bitmap is the images for all the buttons side-by-
side. I've used 18 pixel wide bitmap (per button) as an example but you can use whatever width
you want. The height will be calculated automagically based on the image width you specify in
this call:
MyImageList.Create(IDB_BITMAP, 18, 18, RGB(0x00,0xFF,0x00));
where the first 18 is the per-image width in the list and the second 18 is the grow-by value
when programatically adding bitmaps to the list.
You can use a different transparency color too.
Make sense?
GeneralRe: Bitmaps Pin
BlitzPackage13-Nov-06 14:48
BlitzPackage13-Nov-06 14:48 
GeneralRe: Bitmaps Pin
Mark Salsbery13-Nov-06 15:31
Mark Salsbery13-Nov-06 15:31 
QuestionDialog help needed Pin
locoone12-Nov-06 14:40
locoone12-Nov-06 14:40 
AnswerRe: Dialog help needed Pin
BlitzPackage12-Nov-06 15:01
BlitzPackage12-Nov-06 15:01 
GeneralRe: Dialog help needed [modified] Pin
locoone12-Nov-06 16:41
locoone12-Nov-06 16:41 
GeneralRe: Dialog help needed Pin
BlitzPackage12-Nov-06 17:55
BlitzPackage12-Nov-06 17:55 
GeneralRe: Dialog help needed Pin
locoone12-Nov-06 17:57
locoone12-Nov-06 17:57 
AnswerRe: Dialog help needed Pin
BlitzPackage12-Nov-06 15:04
BlitzPackage12-Nov-06 15:04 
Questionmshflexgrid problem Pin
Tarek Jabri12-Nov-06 3:22
Tarek Jabri12-Nov-06 3:22 
AnswerRe: mshflexgrid problem Pin
S Douglas13-Nov-06 21:59
professionalS Douglas13-Nov-06 21:59 
QuestionMalloc fails...why? Pin
damir_tk12-Nov-06 2:30
damir_tk12-Nov-06 2:30 
AnswerRe: Malloc fails...why? Pin
Taka Muraoka12-Nov-06 2:36
Taka Muraoka12-Nov-06 2:36 
AnswerRe: Malloc fails...why? Pin
Waldermort12-Nov-06 4:22
Waldermort12-Nov-06 4:22 
GeneralRe: Malloc fails...why? Pin
damir_tk12-Nov-06 9:50
damir_tk12-Nov-06 9:50 
AnswerRe: Malloc fails...why? Pin
Mark Salsbery12-Nov-06 8:33
Mark Salsbery12-Nov-06 8:33 
GeneralRe: Malloc fails...why? Pin
damir_tk12-Nov-06 9:55
damir_tk12-Nov-06 9:55 
GeneralRe: Malloc fails...why? Pin
Mark Salsbery12-Nov-06 10:27
Mark Salsbery12-Nov-06 10:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.