Jump to content
  • Advertisement
Sign in to follow this  

Adding Custom bitmaps to my Toolbar

This topic is 3638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have created a bitmap that is 96 by 16 pixels and contains 6 images. I can't seem to find out how to use these images as buttons for a toolbar. I am using Dev-C++ as my compiler. I have figured out how to add images from the CommonControl library. The toolbar section of my code is as follows: ------------------------------------------------------------------------------ HWND hTool; TBBUTTON tbb[3]; TBADDBITMAP tbab; hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL); if(hTool == NULL) MessageBox(hwnd, "Could not create tool bar.", "Error", MB_OK | MB_ICONERROR); // Send the TB_BUTTONSTRUCTSIZE message, which is required for // backward compatibility. SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); tbab.hInst = HINST_COMMCTRL; tbab.nID = IDB_STD_SMALL_COLOR; SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab); ZeroMemory(tbb, sizeof(tbb)); tbb[0].iBitmap = STD_FILENEW; tbb[0].fsState = TBSTATE_ENABLED; tbb[0].fsstyle = TBstyle_BUTTON; tbb[0].idCommand = ID_FILE_NEW; //declared in header tbb[1].iBitmap = STD_FILEOPEN; tbb[1].fsState = TBSTATE_ENABLED; tbb[1].fsstyle = TBstyle_BUTTON; tbb[1].idCommand = ID_FILE_OPEN; //declared in header tbb[2].iBitmap = STD_FILESAVE; tbb[2].fsState = TBSTATE_ENABLED; tbb[2].fsstyle = TBstyle_BUTTON; tbb[2].idCommand = ID_FILE_SAVEAS; //declared in header SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb); ----------------------------------------------------------------------------- That works well, I just can't figure how to do this using my own images.

Share this post

Link to post
Share on other sites
Here's a piece of code from one of my apps:

HWND hWndToolbar = NULL;
TBBUTTON buttons[6];

/* Create image list from a custom bitmap */

HIMAGELIST himlToolbar = ImageList_LoadImage(
g_hInstance, /* App instance handle */
(LPCTSTR)IDB_TOOLBAR,/* ID of your custom bitmap in resources */
16, /* Width of each button image within the bitmap */
1, /* By how much toolbar can grow. I don't use this */
RGB(255, 0, 255), /* Transparent color used in button images. I use magenta */

return 1;

/* Create toolbar */

hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 1, 1, hWnd, NULL, g_hInstance, NULL);

return 1;

/* Attach image list to the toolbar */

SendMessage(hWndToolbar, TB_SETIMAGELIST, 0, (LPARAM)himlToolbar);

/* Set common properties for all buttons */

for(int n = 0; n < 6; n++)
buttons[n].iBitmap = n;
buttons[n].fsState = TBSTATE_ENABLED;
buttons[n].fsStyle = TBSTYLE_BUTTON;
buttons[n].dwData = 0;
buttons[n].iString = 0;

/* Set properties specific to each button */

buttons[0].idCommand = ID_EDITOR_ADD;
buttons[1].idCommand = ID_EDITOR_REMOVE;
buttons[2].idCommand = ID_EDITOR_EDIT;
buttons[3].idCommand = ID_EDITOR_DUPLICATE;
buttons[4].idCommand = ID_EDITOR_SAVE;
buttons[5].idCommand = ID_EDITOR_RELOAD;

/* Tell toolbar the size of button structure */

SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);

/* Add 6 buttons to the toolbar that we initialized earlier */

SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)6, (LPARAM)&buttons);

/* Auto-size the toolbar */

SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!