[RESEND 2] comctl32:imagelist: ImageList_Replace mask fixes

Oleg Krylov oleg.krylov at gmail.com
Thu Aug 17 08:08:22 CDT 2006


Hello,

RESEND: added changelog and license

This patch fixes ImageList_Replace function, which behaved incorrectly 
if mask bitmap is supplied.
Code corrections mostly taken from ImageList_Add function.
Changes include: create additional temporary DC for mask and apply mask 
using BitBlt, not with StretchBlt.
Fixes a part of a Bug#: 4947

Changelog:
- Fix ImageList_Replace function to correctly apply image mask.
Author: Oleg Krylov <oleg.krylov at gmail.com>
License: LGPL

-------------- next part --------------
diff -urN wine/dlls/comctl32/imagelist.c wineNew/dlls/comctl32/imagelist.c
--- wine/dlls/comctl32/imagelist.c	2006-05-23 15:47:37.000000000 +0300
+++ wineNew/dlls/comctl32/imagelist.c	2006-07-27 13:54:30.000000000 +0300
@@ -2158,6 +2158,7 @@
 {
     HDC hdcImage;
     BITMAP bmp;
+    HBITMAP hOldBitmap;
 
     TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
 
@@ -2175,29 +2176,34 @@
     GetObjectA (hbmImage, sizeof(BITMAP), (LPVOID)&bmp);
 
     /* Replace Image */
-    SelectObject (hdcImage, hbmImage);
+    hOldBitmap = SelectObject (hdcImage, hbmImage);
 
     StretchBlt (himl->hdcImage, i * himl->cx, 0, himl->cx, himl->cy,
                   hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
 
     if (himl->hbmMask)
     {
-        /* Replace Mask */
-        SelectObject (hdcImage, hbmMask);
-
-        StretchBlt (himl->hdcMask, i * himl->cx, 0, himl->cx, himl->cy,
-                      hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
-
-
-        /* Remove the background from the image
-        */
-        StretchBlt (himl->hdcImage,
-            i*himl->cx, 0, himl->cx, himl->cy,
-            hdcImage,
-            0, 0, bmp.bmWidth, bmp.bmHeight,
-            0x220326); /* NOTSRCAND */
+        HDC hdcTemp;
+        HBITMAP hOldBitmapTemp;
+
+        hdcTemp   = CreateCompatibleDC(0);
+        hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
+
+        StretchBlt (himl->hdcMask, i * himl->cx, 0, himl->cx, himl->cy,
+                      hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
+        SelectObject(hdcTemp, hOldBitmapTemp);
+        DeleteDC(hdcTemp);
+
+        /* Remove the background from the image
+        */
+        BitBlt (himl->hdcImage,
+            i*himl->cx, 0, bmp.bmWidth, bmp.bmHeight,
+            himl->hdcMask,
+            i*himl->cx, 0,
+            0x220326); /* NOTSRCAND */
     }
 
+    SelectObject (hdcImage, hOldBitmap);
     DeleteDC (hdcImage);
 
     return TRUE;


More information about the wine-patches mailing list