You copy&paste the code and forget to change the assignment:
void AddBitmapToToolbar(int bitmapId)
{
int btnIndex;
....
tbButton.iBitmap = btnIndex;
// tbButton.idCommand = mnuHelpAbout; //This is probably from copy
tbButton.idCommand = bitmapId; //This is what you want
....
// Add the button to the toolbar
SendMessage(hTool, TB_ADDBUTTONS, 1, (LPARAM)&tbButton);
}
Just for info, you can define variables inside a switch statement case, just you need to add braces to define a code block:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// HWND hwndToolbar; //FALSE: Must declare here - not in the switch statement
switch(msg)
{
case WM_CREATE: //initialise window controls etc here if desired
....
case WM_SIZE:
{
HWND hwndToolbar = GetDlgItem(hwnd, IDC_MAIN_TOOL); //You can declare variables inside a switch using braces
SendMessage(hwndToolbar, TB_AUTOSIZE, 0, 0);
break;
}
case WM_CLOSE:
ImageList_Destroy(hImageList);
....
}
More general I suggest to take more care of details in assignment and casting (don't overlook the warnings!).