CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2023
    Posts
    13

    Custom images not appearing in Toolbar buttons

    Hi,
    I'm trying to get my own images in Toolbar buttons but the buttons just have the text. I added the images as resources in the project. Any idea what I am missing? Here is the function (IDB_PNG1 and IDB_PNG2 are the imaged IDs):

    Code:
    HWND CreateToolbar(HWND hWndParent, HINSTANCE g_hInst) {
        // Declare and initialize local constants
        const int ImageListID = 0;
        const int numButtons = 2;
        const DWORD buttonStyles = BTNS_AUTOSIZE;
     
    
        // Create the toolbar
        HWND hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_WRAPABLE, 0, 0, 0, 0, hWndParent, NULL, g_hInst, NULL);
    
        if (hWndToolbar == NULL)
            return NULL;
    
        // Create the image list
        HIMAGELIST hImageList = ImageList_Create(TB_HEIGHT, TB_WIDTH, ILC_COLOR32 | ILC_MASK, numButtons, 1);
    
        // Add your custom image to the image list
        ImageList_Add(hImageList, LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_PNG1)), NULL);
        ImageList_Add(hImageList, LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_PNG2)), NULL);
    
    
        // Associate the image list with the toolbar
        SendMessage(hWndToolbar, TB_SETIMAGELIST, (WPARAM)ImageListID, (LPARAM)hImageList);
     
        // Define the toolbar buttons
        TBBUTTON tbb[numButtons] = {
            { 0, IDB_PNG1, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Start" },
            { 1, IDB_PNG2, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Stop" }
        };
    
        // Add buttons
        SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
        SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)&tbb);
    
        // Resize the toolbar and show it
        SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);
        ShowWindow(hWndToolbar, TRUE);                 
    
        return hWndToolbar;
    } // HWND CreateToolbar(HWND hWndParent)
    Thanks for any advice.
    Last edited by VictorN; March 4th, 2024 at 04:47 PM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,404

    Re: Custom images not appearing in Toolbar buttons

    [added CODE tags]
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2023
    Posts
    13

    Re: Custom images not appearing in Toolbar buttons

    Hi Victor, Sorry, was there an imagein your reply ? Clicking the image to open it gives a 404 error

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,404

    Re: Custom images not appearing in Toolbar buttons

    Quote Originally Posted by notverybright View Post
    Hi Victor, Sorry, was there an imagein your reply ? Clicking the image to open it gives a 404 error

    No don't worry! it was just an image linked to my profile. However this linking does not work anymore (since about 4...5 years)
    Last edited by VictorN; April 6th, 2024 at 01:21 PM.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured