Thread: Toolbar Images

  1. #1
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346

    Toolbar Images

    I have created a toolbar as follows:
    Code:
    TBADDBITMAP Bitmap;
    	TBBUTTON Button[14];
    
    	hTool = CreateWindowEx(0, TOOLBARCLASSNAME, "",
    						WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,
    						0, 0, 0, 0,	hwnd, NULL,	ghInstance,	NULL);
    
    	SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
    
    	Bitmap.hInst = HINST_COMMCTRL;
    	Bitmap.nID = IDB_STD_SMALL_COLOR;
    
    	SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM) &Bitmap);
    
    	ZeroMemory(Button, sizeof(Button));
    
    	Button[0].iBitmap   = STD_FILENEW;
    	Button[0].fsState   = TBSTATE_ENABLED;
    	Button[0].fsStyle   = TBSTYLE_BUTTON;
    	Button[0].idCommand = MENU_FILE_NEW;
    
    	Button[1].iBitmap   = STD_FILEOPEN;
    	Button[1].fsState   = TBSTATE_ENABLED;
    	Button[1].fsStyle   = TBSTYLE_BUTTON;
    	Button[1].idCommand = MENU_FILE_OPEN;
    
    	Button[2].iBitmap   = STD_FILESAVE;
    	Button[2].fsState   = TBSTATE_ENABLED;
    	Button[2].fsStyle   = TBSTYLE_BUTTON;
    	Button[2].idCommand = MENU_FILE_SAVE;
    
    	Button[3].iBitmap   = STD_PRINT;
    	Button[3].fsState   = TBSTATE_ENABLED;
    	Button[3].fsStyle   = TBSTYLE_BUTTON;
    	Button[3].idCommand = MENU_FILE_PRINT;
    
    	Button[4].fsStyle   = TBSTYLE_SEP;
    
    	Button[5].iBitmap   = STD_CUT;
    	Button[5].fsState   = TBSTATE_ENABLED;
    	Button[5].fsStyle   = TBSTYLE_BUTTON;
    	Button[5].idCommand = MENU_EDIT_CUT;
    
    	Button[6].iBitmap   = STD_COPY;
    	Button[6].fsState   = TBSTATE_ENABLED;
    	Button[6].fsStyle   = TBSTYLE_BUTTON;
    	Button[6].idCommand = MENU_EDIT_COPY;
    
    	Button[7].iBitmap   = STD_PASTE;
    	Button[7].fsState   = TBSTATE_ENABLED;
    	Button[7].fsStyle   = TBSTYLE_BUTTON;
    	Button[7].idCommand = MENU_EDIT_PASTE;
    
    	Button[8].fsStyle   = TBSTYLE_SEP;
    
    	Button[9].iBitmap   = STD_UNDO;
    	Button[9].fsState   = TBSTATE_ENABLED;
    	Button[9].fsStyle   = TBSTYLE_BUTTON;
    	Button[9].idCommand = MENU_EDIT_UNDO;
    
    	Button[10].iBitmap   = STD_FIND;
    	Button[10].fsState   = TBSTATE_ENABLED;
    	Button[10].fsStyle   = TBSTYLE_BUTTON;
    	Button[10].idCommand = MENU_SEARCH_FIND;
    
    	Button[11].iBitmap   = STD_REPLACE;
    	Button[11].fsState   = TBSTATE_ENABLED;
    	Button[11].fsStyle   = TBSTYLE_BUTTON;
    	Button[11].idCommand = MENU_SEARCH_REPLACE;
    
    	Button[12].fsStyle   = TBSTYLE_SEP;
    
    	Button[13].iBitmap   = STD_HELP;
    	Button[13].fsState   = TBSTATE_ENABLED;
    	Button[13].fsStyle   = TBSTYLE_BUTTON;
    	Button[13].idCommand = MENU_HELP_TOPIC;
    
    	SendMessage(hTool, TB_ADDBUTTONS, 14, (LPARAM) &Button);
    }
    I would like to change Button[13] to a Bitmap loaded as a resource. Does anyone know how to do this? I tried just changing the iBitmap part of the structure, but this did not work.

    Thanks.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Actually changing the iBitmap is what you have to do. But this part is kinda weird, you need to have your resource name for you image have a #defines with a number. Like this:

    Code:
    #define my_toolbar_image 150
    my_toolbar_image BITMAP "C:/image.bmp"
    It has been my experience that this works.

  3. #3
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    I don't really understand. I thought iBitmap was the zero based index of the bitmap image. I think my problem is that I am trying to have some images be the STD_<imageName> kind and others being custom images that are stored as bitmap resources. I don't know if you can combine these two into one toolbar.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    In that case, I don't think you can use standard images and your images both in the same toolbar. You can make multiple toolbars though.

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Toolbars store and manipulate their images in an imagelist control. In order to 'mix & match' as you have described you need to kill off the current toolbar imagelist and create another that contains the images you require. You attach this new imagelist to the toolbar and access the images in exactly the same manner as previously.

    You can use the TB_SETIMAGELIST to both set the new and retrieve the old imagelist, eg.:

    Code:
    ImageList_Destroy((HIMAGELIST)SendMessage(hToolbar,TB_SETIMAGELIST,0,(LPARAM)NewImageList);
    where hToolbar is your toolbar handle and NewImageList is the handle of the new imagelist.

    One way to get the default images from comctl32.dll is to use LoadLibrary to get an instance handle; use LoadImage with this handle and the image resource id to retrieve handles to the images. Get image handles for your own image(s) using your preferred loading technique and add them to your new image list. Don't forget to FreeLibrary when you're done with comctl32.dll.

    Hope that helps some.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    That is a very good idea! Good thinking Ken.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. toolbar button question
    By supernater in forum Windows Programming
    Replies: 1
    Last Post: 05-25-2009, 08:24 PM
  2. Putting Images In The Toolbar
    By blueterry in forum Windows Programming
    Replies: 0
    Last Post: 06-30-2007, 10:49 AM
  3. Toolbar color
    By mrafcho001 in forum Windows Programming
    Replies: 2
    Last Post: 04-17-2006, 10:55 AM
  4. Dockable Toolbar (Like taskbar or office toolbar)
    By om3ga in forum Windows Programming
    Replies: 2
    Last Post: 11-20-2005, 03:09 AM
  5. Toolbar Buttons
    By G'n'R in forum Windows Programming
    Replies: 2
    Last Post: 10-02-2003, 04:35 AM