-
March 4th, 2024, 12:23 PM
#1
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.
-
March 4th, 2024, 04:49 PM
#2
Re: Custom images not appearing in Toolbar buttons
Victor Nijegorodov
-
March 8th, 2024, 04:16 AM
#3
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
-
March 8th, 2024, 02:31 PM
#4
Re: Custom images not appearing in Toolbar buttons
 Originally Posted by notverybright
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|