From a4944ff123adc3628ae97c78288c4025a4d58402 Mon Sep 17 00:00:00 2001 From: Adam Gundy Date: Fri, 7 Mar 2003 23:02:46 +0000 Subject: [PATCH] TOOLBAR_AddBitmap() and TOOLBAR_ReplaceBitmap() are not supposed to modify the bitmap - we call ImageList_AddMasked() which turns all masked pixels black. Fixed by making a copy of the bitmap to give to ImageList_AddMasked(). --- dlls/comctl32/toolbar.c | 64 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c index d35b2a0c2ee..b417808d806 100644 --- a/dlls/comctl32/toolbar.c +++ b/dlls/comctl32/toolbar.c @@ -2227,9 +2227,34 @@ TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam) /* Add bitmaps to the default image list */ if (lpAddBmp->hInst == NULL) { - nIndex = - ImageList_AddMasked (himlDef, (HBITMAP)lpAddBmp->nID, - CLR_DEFAULT); + BITMAP bmp; + HBITMAP hOldBitmapBitmap, hOldBitmapLoad; + HDC hdcImage, hdcBitmap; + + /* copy the bitmap before adding it so that the user's bitmap + * doesn't get modified. + */ + GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp); + + hdcImage = CreateCompatibleDC(0); + hdcBitmap = CreateCompatibleDC(0); + + /* create new bitmap */ + hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL); + hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID); + hOldBitmapLoad = SelectObject(hdcImage, hbmLoad); + + /* Copy the user's image */ + BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, + hdcBitmap, 0, 0, SRCCOPY); + + SelectObject (hdcImage, hOldBitmapLoad); + SelectObject (hdcBitmap, hOldBitmapBitmap); + DeleteDC (hdcImage); + DeleteDC (hdcBitmap); + + nIndex = ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT); + DeleteObject (hbmLoad); } else if (lpAddBmp->hInst == HINST_COMMCTRL) { @@ -3803,12 +3828,41 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam) /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */ - himlDef = GETDEFIMAGELIST(infoPtr, 0); + himlDef = GETDEFIMAGELIST(infoPtr, 0); for (i = pos + nOldButtons - 1; i >= pos; i--) { ImageList_Remove(himlDef, i); } - ImageList_AddMasked(himlDef, hBitmap, CLR_DEFAULT); + { + BITMAP bmp; + HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad; + HDC hdcImage, hdcBitmap; + + /* copy the bitmap before adding it so that the user's bitmap + * doesn't get modified. + */ + GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp); + + hdcImage = CreateCompatibleDC(0); + hdcBitmap = CreateCompatibleDC(0); + + /* create new bitmap */ + hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL); + hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap); + hOldBitmapLoad = SelectObject(hdcImage, hbmLoad); + + /* Copy the user's image */ + BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, + hdcBitmap, 0, 0, SRCCOPY); + + SelectObject (hdcImage, hOldBitmapLoad); + SelectObject (hdcBitmap, hOldBitmapBitmap); + DeleteDC (hdcImage); + DeleteDC (hdcBitmap); + + ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT); + DeleteObject (hbmLoad); + } InvalidateRect(hwnd, NULL, FALSE);