Add buttons with images to a toolbar

Hi, I have this code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Resources.RC//////////////////////
BITMAP1     BITMAP     "bitmap1.bmp"
////////////////////////////////////

//Resources.h///////////////////////
#define     bitmap1     101
////////////////////////////////////

//Main.cpp//////////////////////////
HWND toolbar;
TBBUTTON toolbar_button;
TBADDBITMAP toolbar_bitmap;

// A lot of code that creates the window

case WM_CREATE:
     toolbar = CreateWindowEx(
                              0, 
                              TOOLBARCLASSNAME, 
                              NULL, 
                              WS_CHILD|WS_VISIBLE, 
                              0, 0, 0, 0, 
                              hWnd, 
                              (HMENU)TOOLBAR, 
                              GetModuleHandle(NULL), 
                              NULL
               );
     SendMessage(toolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
     //The toolbar is created. Everything cool

     toolbar_bitmap.hInst = HINST_COMMCTRL;
     toolbar_bitmap.nID = BITMAP1;
     toolbar_bitmap = SendMessage(toolbar, TB_ADDBITMAP, 1, (LPARAM)&toolbar_bitmap);

     tb_username.iBitmap = 0;
     tb_username.fsState = TBSTATE_ENABLED;
     tb_username.fsStyle = TBSTYLE_BUTTON;
     tb_username.idCommand = MNU_BUTTON1;
break;
//////////////////////////////////// 


My problem is that the toolbar is created, the button is created but the icon doesn't appear on it. It's like something is missing. Somebody can give me some clues. Thanks!
1. Always check the return value of functions. Check the return value of SendMessage() to see if it was successful. See http://msdn.microsoft.com/en-us/library/windows/desktop/bb787289(v=vs.85).aspx .
2. TBADDBITMAP::hInst is the HINSTANCE of the module containing the bitmap resource. I doubt that HINST_COMMCTRL is the HINSTANCE of your executable. It must be the one for your executable. Also noted in the link above.

And I guess it should work after that.
Yes, it was that. Now I understand instaces better. Thanks!
Topic archived. No new replies allowed.