Subj : Re: Help with API toolbar To : borland.public.cpp.borlandcpp From : Jeff Baker Date : Thu Jun 10 2004 01:58 pm Well I can't seem to get it done with an index BMP but I did figure out one way to get it done. Here is the code listing that lets you make a custom toolbar with Win32 API. The code listing should be placed under WM_CREATE. This listing works for 16x16 buttons. Trying to change ICON_X or ICON_Y to anything other then 16 doesn't seem to work. If I set the value of these to 32 (or any other value) the buttons will get bigger but the toolbar itself stays the same. This leaves me with only half the button being displayed. Anyone know why that is? [START OF CODE] // enternal defines for TOTAL_ICONS, ICON_X, ICON_Y, ID_BUTTON_0, ID_BUTTON_1, ID_BUTTON_2, // external individual bitmaps: IDB_BUTTON_0, IDB_BUTTON_1, IDB_BUTTON_2 // external int: button0, button1, button2 // Toolbar ID = IDC_MAIN_TOOL HWND hTool; //handle to our toolbar TBBUTTON tbb[TOTAL_ICONS]; //array to hold our 2 toolbar buttons HBITMAP hbmBmp; g_himlIcons = ImageList_Create(ICON_X,ICON_Y,ILC_COLOR,TOTAL_ICONS,0); //first we have to make our imagelist which holds our customs icons hbmBmp = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BUTTON_0)); //then we load each icon into the imagelist button0 = ImageList_Add(g_himlIcons,hbmBmp,NULL); DeleteObject(hbmBmp); hbmBmp = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BUTTON_1)); button1 = ImageList_Add(g_himlIcons,hbmBmp,NULL); DeleteObject(hbmBmp); hbmBmp = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BUTTON_2)); button2 = ImageList_Add(g_himlIcons,hbmBmp,NULL); DeleteObject(hbmBmp); hTool = CreateWindowEx(0,TOOLBARCLASSNAME,NULL,WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,(HME NU)IDC_MAIN_TOOL,GetModuleHandle(NULL),NULL); //now let's create the actual toolbar if(!hTool) MessageBox(hwnd,"Error Creating Toolbar","Error",MB_OK|MB_ICONERROR); SendMessage(hTool,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0); //this message is required for backward compatibility SendMessage(hTool,TB_SETIMAGELIST,0,(LPARAM)g_himlIcons); //now we tell the toolbar which imagelist to use for the default state of buttons ZeroMemory(&tbb,sizeof(tbb)); //now lets setup the buttons to use our custom bitmaps tbb[0].iBitmap = button0; //index to the first bitmap we added to imagelist tbb[0].idCommand = ID_BUTTON_0; tbb[0].fsState = TBSTATE_ENABLED; tbb[0].fsStyle = TBSTYLE_BUTTON; tbb[1].iBitmap = button1; //index to second bitmap we added to imagelist tbb[1].idCommand = ID_BUTTON_1; tbb[1].fsState = TBSTATE_ENABLED; tbb[1].fsStyle = TBSTYLE_BUTTON; tbb[2].iBitmap = button2; //index to third bitmap we added to imagelist tbb[2].idCommand = ID_BUTTON_2; tbb[2].fsState = TBSTATE_ENABLED; tbb[2].fsStyle = TBSTYLE_BUTTON; SendMessage(hTool, TB_ADDBUTTONS, TOTAL_ICONS, (LPARAM)&tbb); //now put the buttons on the toolbar [END OF CODE] Does anyone know how to step through an indexed BMP file thus filling the TBBUTTON structure with one single indexed bitmap (a single bitmap file containing more then one image)? .