Reputation: 10037
I'm experiencing some strange behaviour with Win32's Toolbar class. On low DPI displays I want my toolbar to use icons in 24x24 pixels and on higher DPI displays I want my toolbar to use icons in 48x48 pixels.
My code looks like this:
tbil = ImageList_Create(icsize, icsize, ILC_COLOR32, 32, 32);
for(k = 0; k < sizeof(tblist) / sizeof(int); k++) {
hi = LoadIcon(hInstance, MAKEINTRESOURCE(tblist[k]));
ImageList_AddIcon(tbil, hi);
}
hToolbarWnd = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD|TBSTYLE_FLAT|TBSTYLE_TOOLTIPS|CCS_NORESIZE|CCS_NODIVIDER, 0, 0, 0, 0, hwnd, NULL, hInstance, NULL);
SendMessage(hToolbarWnd, TB_SETIMAGELIST, 0, (LPARAM) tbil);
SendMessage(hToolbarWnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
SendMessage(hToolbarWnd, TB_ADDBUTTONS, (WPARAM) sizeof(tbButton) / sizeof(TBBUTTON), (LPARAM) tbButton);
The icsize
variable is set to either 24 or 48, depending on the current DPI settings.
The icons that are loaded from my resources contain two images each: One in 24x24 and one in 48x48 and I'm expecting ImageList_AddIcon()
to choose the correct one but apparently this isn't the case because what happens is this: On low DPI systems (i.e. systems that should use 24x24 icons) ImageList_AddIcon()
still adds the 48x48 icon but scales it down to 24x24 which looks ugly of course.
Is this the way it is supposed to be? If it is, how am I supposed to deal with it? Do I have to use separate *.ico files? One for 24x24 and one for 48x48 instead of combining both sizes inside a single *.ico file? It's a little confusing and I don't see this documented anywhere.
Thanks for any help.
Upvotes: 1
Views: 144
Reputation: 51345
Even though .ICO files and icon resources (potentially) consist of multiple icon directory entries, LoadIcon will only load a single icon. And it loads icons at the system default size only. This is documented, too:
LoadIcon can only load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric values.
Next to this is the solution as well:
Use the LoadImage function to load icons of other sizes.
Bonus reading:
Upvotes: 3