[IMAGESOFT] Commit db416e39 made toolbar imagelists creating failing because we overcounted the number of toolbar button bitmaps.

Indeed the count was based on the number of elements in TBBUTTON arrays;
however for some of the toolbars, extra entries corresponding to
separators are present, and thus the resulting number of elements is
always larger than the number of actual buttons for which an image is
associated. Passing this (larger) count to the InitImageList() function
therefore made image insertion fail after a certain point.

Now we pass an exact number of *images* instead.
This commit is contained in:
Hermès Bélusca-Maïto 2021-09-26 02:26:42 +02:00
parent 970344bd16
commit 67fd29cae0
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 13 additions and 15 deletions

View file

@ -56,7 +56,7 @@ FloatToolbarCreateToolsGui(PMAIN_WND_INFO Info)
{
HWND hTb;
HIMAGELIST hImageList;
INT NumButtons;
UINT NumButtons;
NumButtons = sizeof(ToolsButtons) / sizeof(ToolsButtons[0]);
@ -86,8 +86,7 @@ FloatToolbarCreateToolsGui(PMAIN_WND_INFO Info)
0,
(LPARAM)MAKELONG(16, 16));
hImageList = InitImageList(NumButtons,
IDB_TOOLSRECTSEL);
hImageList = InitImageList(IDB_TOOLSRECTSEL, NumButtons - 1); // -1 because of the last separator.
ImageList_Destroy((HIMAGELIST)SendMessage(hTb,
TB_SETIMAGELIST,
@ -280,7 +279,7 @@ FloatToolbarCreateHistoryGui(PMAIN_WND_INFO Info)
HWND hList;
HWND hButtons;
HIMAGELIST hImageList;
INT NumButtons;
UINT NumButtons;
hList = CreateWindowEx(0,
WC_LISTBOX,
@ -316,8 +315,7 @@ FloatToolbarCreateHistoryGui(PMAIN_WND_INFO Info)
0,
(LPARAM)MAKELONG(10, 10));
hImageList = InitImageList(NumButtons,
IDB_HISTBACK);
hImageList = InitImageList(IDB_HISTBACK, NumButtons);
ImageList_Destroy((HIMAGELIST)SendMessage(hButtons,
TB_SETIMAGELIST,

View file

@ -119,6 +119,7 @@ MainWndCreateToolbarClient(struct _TOOLBAR_DOCKS *TbDocks,
const TBBUTTON *Buttons = NULL;
UINT NumButtons = 0;
UINT StartImageRes = 0;
UINT NumImages = 0;
HWND hWndClient = NULL;
UNREFERENCED_PARAMETER(Context);
@ -130,6 +131,7 @@ MainWndCreateToolbarClient(struct _TOOLBAR_DOCKS *TbDocks,
Buttons = StdButtons;
NumButtons = sizeof(StdButtons) / sizeof(StdButtons[0]);
StartImageRes = IDB_MAINNEWICON;
NumImages = 10;
break;
}
@ -138,6 +140,7 @@ MainWndCreateToolbarClient(struct _TOOLBAR_DOCKS *TbDocks,
Buttons = TextButtons;
NumButtons = sizeof(TextButtons) / sizeof(TextButtons[0]);
StartImageRes = IDB_TEXTBOLD;
NumImages = 6;
break;
}
@ -194,8 +197,7 @@ MainWndCreateToolbarClient(struct _TOOLBAR_DOCKS *TbDocks,
0,
(LPARAM)MAKELONG(TB_BMP_WIDTH, TB_BMP_HEIGHT));
hImageList = InitImageList(NumButtons,
StartImageRes);
hImageList = InitImageList(StartImageRes, NumImages);
ImageList_Destroy((HIMAGELIST)SendMessage(hWndClient,
TB_SETIMAGELIST,

View file

@ -372,7 +372,8 @@ ToolbarInsertSpaceForControl(HWND hWndToolbar,
HIMAGELIST
InitImageList(UINT NumImages, UINT StartResource)
InitImageList(UINT StartResource,
UINT NumImages)
{
UINT EndResource = StartResource + NumImages - 1;
HBITMAP hBitmap;
@ -390,7 +391,7 @@ InitImageList(UINT NumImages, UINT StartResource)
return NULL;
/* Add all icons to the image list */
for (i = StartResource; i <= EndResource; i++)
for (i = StartResource; i <= EndResource && Ret != -1; i++)
{
hBitmap = LoadImage(hInstance,
MAKEINTRESOURCE(i),
@ -409,9 +410,6 @@ InitImageList(UINT NumImages, UINT StartResource)
RGB(255, 255, 254));
DeleteObject(hBitmap);
if (Ret == -1)
break;
}
if (Ret == -1)

View file

@ -40,5 +40,5 @@ BOOL ToolbarInsertSpaceForControl(HWND hWndToolbar,
INT iCmd,
BOOL HideVertical);
HIMAGELIST InitImageList(UINT NumButtons,
UINT StartResource);
HIMAGELIST InitImageList(UINT StartResource,
UINT NumImages);