Okay, I have been googling and looking on MSDN for this for a couple hours or so, and I will continue to do so until somebody replies. I need some help on a program I am making in my free time.

Can sombody tell me what would be a good way to create my own icon list to use in a toolbar. I have a toolbar, and I don't like the look of the IDB_STD_SMALL_COLOR icon list. I would really like to make my own, and I can make the icons, I just need to know how I can create my own list of icons. But there is a catch, it can't use any resource scripts.

I am not looking for somebody to just hand me a script and say "here you go", I would like either a small tutorial by you, or a link to a tutorial.

I have an idea of how I could do it:

TBBUTTON btn[12];
    TBADDBITMAP bmp;
    HINSTANCE hInst = GetModuleHandle(NULL);
    
    bmp.hInst = hInst;
    //bmp.nID = IDB_STD_LARGE_COLOR; // Can I just not set nID?
    SendMessage(toolbar, TB_ADDBITMAP, 0, (LPARAM)&bmp);
    ZeroMemory(btn, sizeof(btn));
    
    btn[0].iBitmap = LoadIcon(hInst, "new.ico");
    btn[0].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
    btn[0].fsStyle = TBSTYLE_BUTTON;
    btn[0].idCommand = CTRL_MENU_FILE_NEW;
    // ...

But this doesn't work, because iBitmap is an integer. So there must be some way. I have heard of image lists, and looked them up on MSDN, but I don't understand them. They are just numbers, where do the actual filenames come into play?

Summary: How to set my own icons for a toolbar.

Dani AI

Generated

Short answer: TBBUTTON::iBitmap is a zero-based image index, not a handle — you cannot put an HICON or HBITMAP directly there. You have two runtime options (no resource script needed): supply a bitmap strip with TB_ADDBITMAP, or build an image list at runtime, add your icons, and attach it with TB_SETIMAGELIST. (learn.microsoft.com)

Recommended (and most flexible) approach: create an image list, load each .ico from disk with LoadImage(..., LR_LOADFROMFILE), add the icon to the image list (ImageList_AddIcon) and then set that image list on the toolbar. That way iBitmap is simply the image index you got back from ImageList_AddIcon. Use ILC_COLOR32|ILC_MASK if you need 32-bit icons/alpha (and ensure the common-controls version/manifest supports it). (learn.microsoft.com)

Example sketch (runtime loading, then adding one button):

INITCOMMONCONTROLSEX icc = { sizeof(icc), ICC_BAR_CLASSES };
InitCommonControlsEx(&icc);

HWND hTB = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD|WS_VISIBLE|TBSTYLE_TOOLTIPS, ...);
SendMessage(hTB, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);

// create imagelist, load icon file, add to list, attach it to toolbar
HIMAGELIST himl = ImageList_Create(16,16, ILC_COLOR32|ILC_MASK, 0, 4);
HICON hIcon = (HICON)LoadImage(NULL, "icons\\new.ico", IMAGE_ICON, 16,16, LR_LOADFROMFILE);
int idx = ImageList_AddIcon(himl, hIcon);
DestroyIcon(hIcon);             // safe after ImageList_AddIcon
SendMessage(hTB, TB_SETIMAGELIST, 0, (LPARAM)himl);

// create button that uses the imagelist index
TBBUTTON tb = {};
tb.iBitmap = idx;
tb.idCommand = IDM_NEW;
tb.fsStyle = BTNS_BUTTON;
tb.fsState = TBSTATE_ENABLED;
SendMessage(hTB, TB_ADDBUTTONS, 1, (LPARAM)&tb);

Troubleshooting notes: call InitCommonControlsEx first, send TB_BUTTONSTRUCTSIZE before TB_ADDBUTTONS if you used CreateWindowEx, and don’t mix TB_ADDBITMAP/CreateToolbarEx with TB_SETIMAGELIST (they conflict). If you prefer a single strip bitmap, load it to an HBITMAP and pass it via TBADDBITMAP (hInst = NULL, nID = (UINT_PTR)hbm). Remember to keep/destroy the image-list or bitmaps at shutdown. (learn.microsoft.com)

— the main bug in your attempt was trying to assign an icon handle to iBitmap; switch to the runtime image-list or TB_ADDBITMAP pattern above and iBitmap will be the numeric index returned when you add the image.

Why isn't anybody answering me? This was the last place I looked and still nobody cares. It's not like I haven't tried, I have worked my ass of trying to do this. I know somebody knows how to do this, and several people who do saw my thread and didn't bother to help.

I got my icons, and I define the bitmap an define the offset in the iBitmap property, but it still doesn't work, and I was following a tutorial. I can't find any other place that has information on this.

They all use the STD library.

So seriously, somebody answer me please.

commented: Â -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.