Release 980413

Sun Apr 12 12:22:23 1997  Andreas Mohr <100.30936@germany.net>

	* [files/drive.c]
	Fixed "no free space" problem with partition sizes between 1 and 2 GB
	(cluster_sectors may not exceed 0x40).

	* [windows/msgbox.c] [if1632/user.spec] [include/windows.h]
	Implemented MessageBoxIndirect16, corrected MSGBOXPARAMS16.

	* [loader/task.c]
	DOS environment strings may never exceed 127 chars
	-> truncate Unix environment strings if necessary.

Sun Apr 12 02:51:44 1998  Dimitrie O. Paun  <dimi@mail.cs.toronto.edu>

	* [files/*.c]
	All fprintf statements were converted to appropriate debug
	messages.

	* [tools/find_debug_channels]
	Updated comments at the beginning of the file.

Sat Apr 11 15:27:21 1998  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [loader/module.c] [loader/task.c] [scheduler/process.c]
	Moved some code around to prepare the ground for CreateProcess().

	* [memory/environ.c] [loader/task.c]
	Moved Win32 environment strings functions to environ.c.
	Unified Win16 and Win32 environment management.

	* [scheduler/handle.c] [scheduler/k32obj.c] [scheduler/*.c]
	Implemented handle inheritance and DuplicateHandle().

	* [scheduler/thread.c]
	Create a 16-bit stack for all threads.

	* [windows/dialog.c]
	Implemented DIALOGEX resource format.

Fri Apr 10 20:21:51 1998  Marcus Meissner <marcus@mud.de>

	* [configure.in][include/acconfig.h][*/*][multimedia/*]
	Cleaned up the OSS detection stuff, added some more checks for
	headerfiles/functions.
	Removed a lot of OS specific #ifdefs.
	Lots of dependend multimedia cleanups.

	* [loader/pe_image.c]
	Enhanced comment, added missing reference count increase.

	* [ole/compobj.c]
	Replaced broken StringFromGUID2 by working one.

	* [misc/winsock.c]
	SO_LINGER uses unsigned 16 bit in Win16 and Win32, but unsigned
	int (32bit) for UNIX.

	* [memory/global.c]
	Allow realloc for lockcount 1 too.

Fri Apr 10 15:27:34 1998  Morten Welinder  <terra@diku.dk>

	* [graphics/x11drv/text.c]
	Handle control characters in trace.  Ignore terminating newline.

	* [multimedia/init.c]
	(MULTIMEDIA_Init): Correct allocations.

	* [tools/examine-relay]
 	Tidy up.

	* [windows/syscolor.c]
	Change highlight colour from lightblue to lightgray.  This
	looks correct for menus.

Fri Apr 10 01:49:58 1998  Douglas Ridgway  <ridgway@winehq.com>

	* [configure.in] [Make.rules.in]
	Add check for c2man before using it.

Fri Apr 10 02:59:21 1998  Douglas Ridgway  <ridgway@winehq.com>

	* [DEVELOPERS-HINTS]
	Simple description of adding API calls.

	* [include/wintypes.h] [include/windows.h]
	Get rid of Winelib16, avoid declaring some illegal functions in
	Winelib, add prototypes for some enhanced metafile functions, fix
	GetTextExtentPoint32 declarations.

	* [relay32/gdi32.spec] [objects/enhmetafile.c]
	Cosmetic and functional improvements.

	* [include/wincon.h] [programs/view/*]
	Fixes, improved compatibility with native compilers.

Thu Apr  9 15:48:49 1998  Ulrich Weigand <weigand@informatik.uni-erlangen.de>

	* [win32/kernel32.c]
	Implemented FT_Thunk / FT_Prolog / FT_Exit / FT_PrologPrime.
	Fixed Common32ThkLS thunk function.

	* [tools/build.c] [relay32/relay386.c] [if1632/relay.c]
	Changed relay code to allow register functions to modify stack layout.

	* [memory/selector.c]
	Implemented AllocMappedBuffer / FreeMappedBuffer.

	* [relay32/kernel32.spec] [if1632/kernel.spec] [win32/ordinals.c]
	Added names for undocumented functions.

	* [loader/module.c]
	Bugfix: LoadLibrary16 should *not* silently load 32-bit DLL.

Thu Apr  9 03:54:58 1998  Jim Peterson <jspeter@birch.ee.vt.edu>

	* [windows/keyboard.c]
	Fix an erroneous test in TranslateAccelerator{16,32} for the end
	of the accelerator table.

Thu Apr  8 20:36:28 1998  Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de> 

	* [misc/crtdll.c]
	Implement getenv.

	* [misc/commdlg.c]
	Make Get[Save/Open]FileName work in most situations.

	* [misc/lstr.c]
	Use wvsprintf32A instead of vsprintf in FormatMessage32X

	* [misc/version]
	Make NT3.50 a recognised version

	* [graphics/x11drv/graphics.c]
	Change the algorithme to draw arcs

	* [loader/resource.c]
	Return an empty buffer in LoadString32A if no resource found.

	* [win32/code_page.c]
	Try harder to get the right size in MultiByteToWideChar.

	* [win32/process.c]
	Call WinExec32 for CreateProcess32A.

	* [windows/user.c]
	Install default Int0 Handler in InitApp().

Thu Apr  8 19:29:48 1998  Eric Kohl <ekohl@abo.rhein-zeitung.de>

	* [misc/imagelist.c]
	Preliminary fix for drawing selected images.
	Various improvements.

	* [controls/progress.c][include/progress.c][include/commctrl.h]
	Added progress bar messages and styles for IE4.01 (dll version 4.72)
	compatibility.
	Fixed led size problem.

	* [controls/updown.c][include/commctrl.h]
	Added UDM_GETRANGE32 and UDM_SETRANGE32.

	* [objects/oembitmaps.c][include/windows.h][include/bitmaps/*]
	Added Win95 icons and fixed Win95 cursor and restore button bug.
	Now they should be visible. Sorry!!!

	* [relay32/comctl32.spec]
	Added most missing function names.

Tue Apr  6 18:48:36 1998  Matthew Becker <mbecker@glasscity.net>

	* [objects/font.c] [if1632/gdi.spec]
	GetOutlineTextMetrics: stub

	* [objects/text.c]
	GetTextCharset should just call GetTextCharsetInfo.

	* [misc/mpr.c] [relay32/mpr.spec]
	WNetCachePassword: stub

	* [scheduler/thread.c] [relay32/user32.spec]
	AttachThreadInput: stub
	Updated documentation.

	* [objects/palette.c]
	Updated documentation.

Tue Mar 31 17:06:30 1998  James Juran <jrj120@psu.edu>

	* [*/*.c]
	Finished fixing USER32 ordinal numbers in function documentation.

Mon Mar 30 20:27:38 1998  Morten Welinder  <terra@diku.dk>

	* [misc/debugstr.c] [include/debugstr.h]
	Moved _dumpstr from relay32/relay386.c.  Improved control
	character handling.

	* [msdos/int21.c]
	Implement 215E00 -- get machine name.

	* [windows/winpos.c]
	SetWindowPos32: Make an extra sync when mapping managed
	windows.  This makes sure the reconfigure event has been
	handled.  See Mshearts' what's-your-name window.

Mon Mar 30 01:13:50 1998  Alexander V. Lukyanov <lav@long.yar.ru>

	* [Makefile.in]
	Install includes from TOPSRCDIR.
diff --git a/misc/imagelist.c b/misc/imagelist.c
index db4c8b4..474de9e 100644
--- a/misc/imagelist.c
+++ b/misc/imagelist.c
@@ -5,28 +5,21 @@
  *
  *  TODO:
  *    - Improve the documentation.
- *    - Fix ImageList_DrawIndirect.
- *        - Drawing selected images is awfully slow since it has to
- *          be done pixel by pixel.
- *    - Fix ImageList_GetIcon (almost fixed).
- *    - Fix all other stubs.
+ *    - Improve error checking in some functions.
+ *    - Fix ILD_TRANSPARENT error in ImageList_DrawIndirect.
+ *    - Fix offsets in ImageList_DrawIndirect.
+ *    - Fix ImageList_GetIcon (might be a result of the
+ *      ILD_TRANSPARENT error in ImageList_DrawIndirect).
  *    - Fix drag functions.
- *    - Improve error checking in most functions.
+ *    - Fix all other stubs.
  *    - Add ImageList_SetFilter (undocumented).
  *      BTW does anybody know anything about this function???
  *        - It removes 12 Bytes from the stack (3 Parameters).
  *        - First parameter SHOULD be a HIMAGELIST.
  *        - Second parameter COULD be an index?????
  *        - Third parameter.... ?????????????????????
- *    - Add undocumented functions.
- *        Are there any other undocumented ImageList functions?
  *
  *  Testing:
- *    - Test ImageList_LoadImageA/W with Icons and Cursors.
- *    - Test ImageList_Copy.
- *    - Test ImageList_Duplicate.
- *    - Test ImageList_Remove.
- *    - Test ImageList_SetImageCount.
  *    - Test ImageList_GetImageRect (undocumented).
  *    - Test all the other functions.
  *
@@ -54,7 +47,6 @@
 #include "imagelist.h"
 #include "commctrl.h"
 #include "debug.h"
-#include "heap.h"
 
 #ifdef __GET_ICON_INFO_HACK__
 #include "bitmap.h"
@@ -76,8 +68,16 @@
 static HCURSOR32  hcurInternal = 0;
 
 
-static void
-IMAGELIST_InternalGrowBitmaps (HIMAGELIST himl, INT32 nImageCount)
+/*************************************************************************
+ *	 		 IMAGELIST_InternalGrowBitmaps   [Internal]
+ *
+ *  Grows the bitmaps of the given image list by the given number of 
+ *  images. Can NOT be used to reduce the number of images.
+ */
+
+static void IMAGELIST_InternalGrowBitmaps (
+	HIMAGELIST himl,    /* image list handle */
+	INT32 nImageCount)  /* number of images to grow by */
 {
     HDC32     hdcImageList, hdcBitmap;
     HBITMAP32 hbmNewBitmap;
@@ -126,44 +126,14 @@
 }
 
 
-static void
-IMAGELIST_InternalDrawMask (HIMAGELIST himl, INT32 i, HDC32 hdc,
-                            INT32 x, INT32 y)
-{
-    HDC32 hdcImageList;
-
-    if (himl->hbmMask)
-    {
-        hdcImageList = CreateCompatibleDC32 (0);
-        SelectObject32 (hdcImageList, himl->hbmMask);
-        BitBlt32 (hdc, x, y, himl->cx, himl->cy, hdcImageList,
-                  himl->cx * i, 0, SRCCOPY);
-        DeleteDC32 (hdcImageList);
-    }  
-}
-
-
-static void
-IMAGELIST_InternalDrawImage (HIMAGELIST himl, INT32 i, HDC32 hdc,
-                             INT32 x, INT32 y, UINT32 fStyle)
-{
-    HDC32 hdcImageList;
-
-    hdcImageList = CreateCompatibleDC32 (0);
-    SelectObject32 (hdcImageList, himl->hbmImage);
-    BitBlt32 (hdc, x, y, himl->cx, himl->cy, hdcImageList,
-              himl->cx * i, 0, SRCCOPY);
-    DeleteDC32 (hdcImageList);
-}
-
-
 /*************************************************************************
  *	 		 ImageList_Add   [COMCTL32.39]
  *
  *  Add an image (and a mask) to an image list.
  *
  *  RETURNS
- *    Index of the first image that was added, -1 if an error occurred.
+ *    Index of the first image that was added.
+ *    -1 if an error occurred.
  */
 
 INT32 WINAPI ImageList_Add (
@@ -174,17 +144,17 @@
     HDC32    hdcImageList, hdcImage, hdcMask;
     INT32    nFirstIndex, nImageCount;
     INT32    nStartX, nRunX, nRunY;
-    COLORREF clrColor;
     BITMAP32 bmp;
 
     if (himl == NULL) return (-1);
 
+    hdcMask = 0; /* to keep compiler happy ;-) */
+
     GetObject32A (hbmImage, sizeof(BITMAP32), (LPVOID)&bmp);
     nImageCount = bmp.bmWidth / himl->cx;
 
     if (himl->cCurImage + nImageCount >= himl->cMaxImage)
         IMAGELIST_InternalGrowBitmaps (himl, nImageCount);
-//        ImageList_SetImageCount (himl, himl->cCurImage + nImageCount);
 
     hdcImageList = CreateCompatibleDC32 (0);
     hdcImage = CreateCompatibleDC32 (0);
@@ -203,6 +173,21 @@
             SelectObject32 (hdcImage, hbmMask);
             BitBlt32 (hdcImageList, himl->cCurImage * himl->cx, 0,
                       bmp.bmWidth, himl->cy, hdcImage, 0, 0, SRCCOPY);
+
+            /* fix transparent areas of the image bitmap*/
+            SelectObject32 (hdcMask, himl->hbmMask);
+            SelectObject32 (hdcImage, himl->hbmImage);
+            nStartX = himl->cCurImage * himl->cx;
+            for (nRunY = 0; nRunY < himl->cy; nRunY++)
+            {
+                for (nRunX = 0; nRunX < bmp.bmWidth; nRunX++)
+                {
+                    if (GetPixel32 (hdcMask, nStartX + nRunX, nRunY) ==
+                        RGB(255, 255, 255))
+                        SetPixel32 (hdcImage, nStartX + nRunX, nRunY, 
+                                    RGB(0, 0, 0));
+                }
+            }
         }
         else
         {
@@ -214,8 +199,8 @@
             {
                 for (nRunX = 0; nRunX < bmp.bmWidth; nRunX++)
                 {
-                    clrColor = GetPixel32 (hdcImageList, nStartX + nRunX, nRunY);
-                    if (clrColor == himl->clrBk)
+                    if (GetPixel32 (hdcImageList, nStartX + nRunX, nRunY) ==
+                        himl->clrBk)
                     {
                         SetPixel32 (hdcImageList, nStartX + nRunX, nRunY, 
                                     RGB(0, 0, 0));
@@ -248,7 +233,8 @@
  *  mask color.
  *
  *  RETURNS
- *    Index of the first image that was added, -1 if an error occurred.
+ *    Index of the first image that was added.
+ *    -1 if an error occurred.
  */
 
 INT32 WINAPI ImageList_AddMasked (
@@ -260,7 +246,6 @@
     INT32    nIndex, nImageCount;
     BITMAP32 bmp;
     INT32    nStartX, nRunX, nRunY;
-    COLORREF clrColor;
 
     if (himl == NULL) return (-1);
 
@@ -291,8 +276,8 @@
         {
             for (nRunX = 0; nRunX < bmp.bmWidth; nRunX++)
             {
-                clrColor = GetPixel32 (hdcImageList, nStartX + nRunX, nRunY);
-                if (clrColor == clrMask)
+                if (GetPixel32 (hdcImageList, nStartX + nRunX, nRunY) ==
+                    clrMask)
                 {
                     SetPixel32 (hdcImageList, nStartX + nRunX, nRunY,
                                 RGB(0, 0, 0));
@@ -316,8 +301,11 @@
 /*************************************************************************
  *	 		 ImageList_BeginDrag   [COMCTL32.42]
  *
- * Creates a temporary imagelist with an image in it, which will be used
- * as a drag image.
+ *  Creates a temporary imagelist with an image in it, which will be used
+ *  as a drag image.
+ *
+ *  RETURNS
+ *    ...
  */
 
 BOOL32 WINAPI ImageList_BeginDrag (
@@ -377,6 +365,9 @@
  *  Copying from one imagelist to another is allowed, in contrary to
  *  M$'s original implementation. They just allow copying or swapping
  *  within one imagelist (himlDst and himlSrc must be the same).
+ *
+ *  RETURNS
+ *    ...
  */
 
 BOOL32 WINAPI ImageList_Copy (
@@ -491,7 +482,8 @@
  *  Creates an imagelist of the given image size and number of images.
  *
  *  RETURNS
- *    Handle of the created image list, 0 if an error occurred.
+ *    Handle of the created image list.
+ *    0 if an error occurred.
  */
 
 HIMAGELIST WINAPI ImageList_Create (
@@ -505,6 +497,13 @@
     HIMAGELIST himl;
     HDC32      hdc;
     INT32      nCount;
+    HBITMAP32  hbmTemp;
+    WORD       aBitBlend25[16] = 
+        {0x7777, 0xDDDD, 0x7777, 0xDDDD, 0x7777, 0xDDDD, 0x7777, 0xDDDD,
+         0x7777, 0xDDDD, 0x7777, 0xDDDD, 0x7777, 0xDDDD, 0x7777, 0xDDDD};
+    WORD       aBitBlend50[16] =
+        {0x5555, 0xAAAA, 0x5555, 0xAAAA, 0x5555, 0xAAAA, 0x5555, 0xAAAA,
+         0x5555, 0xAAAA, 0x5555, 0xAAAA, 0x5555, 0xAAAA, 0x5555, 0xAAAA};
 
     himl = (HIMAGELIST)LocalAlloc32 (LMEM_FIXED | LMEM_ZEROINIT,
                                      sizeof(struct _IMAGELIST));
@@ -553,6 +552,15 @@
     else
         himl->hbmMask = 0;
 
+    /* create blending brushes */
+    hbmTemp = CreateBitmap32 (16, 16, 1, 1, &aBitBlend25);
+    himl->hbrBlend25 = CreatePatternBrush32 (hbmTemp);
+    DeleteObject32 (hbmTemp);
+
+    hbmTemp = CreateBitmap32 (16, 16, 1, 1, &aBitBlend50);
+    himl->hbrBlend50 = CreatePatternBrush32 (hbmTemp);
+    DeleteObject32 (hbmTemp);
+
     return (himl);    
 }
 
@@ -563,7 +571,8 @@
  *  Destroy the given imagelist.
  *
  *  RETURNS
- *    TRUE if the image list was destryed, FALSE if an error occurred.
+ *    TRUE if the image list was destroyed.
+ *    FALSE if an error occurred.
  */
 
 BOOL32 WINAPI ImageList_Destroy (
@@ -614,7 +623,6 @@
     FIXME (imagelist, "empty stub!\n");
 
 
-
     SetCursor32 (hcurInternal);
     hcurInternal = 0;
  
@@ -727,23 +735,24 @@
 
 
 /*************************************************************************
- *	 		 ImageList_Drawindirect   [COMCTL32.52]
+ *	 		 ImageList_DrawIndirect   [COMCTL32.52]
  */
 
 BOOL32 WINAPI ImageList_DrawIndirect (
 	IMAGELISTDRAWPARAMS *pimldp)
 {
     HIMAGELIST himlLocal;
-    HDC32      hdcImageList,hdcMask, hdcTempImage;
-    HBITMAP32  hbmMask, hbmTempImage;
+    HDC32      hdcImageList, hdcTempImage;
+    HBITMAP32  hbmTempImage;
     HBRUSH32   hBrush, hOldBrush;
-    INT32      nOvlIdx, nStartX, nRunX, nRunY;
-    COLORREF   clrBlend, clrImage;
+    INT32      nOvlIdx;
+    COLORREF   clrBlend;
     BOOL32     bImage;       /* draw image ? */
     BOOL32     bImageTrans;  /* draw image transparent ? */
     BOOL32     bMask;        /* draw mask ? */
     BOOL32     bMaskTrans;   /* draw mask transparent ? */
-    BOOL32     bBlend = FALSE;
+    BOOL32     bBlend25;
+    BOOL32     bBlend50;
 
     if (pimldp == NULL) return (FALSE);
     if (pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS)) return (FALSE);
@@ -755,6 +764,8 @@
     bImageTrans = FALSE;
     bMask       = FALSE;
     bMaskTrans  = FALSE;
+    bBlend25    = FALSE;
+    bBlend50    = FALSE;
     if ((himlLocal->clrBk == CLR_NONE) && (himlLocal->hbmMask))
     {
         bImageTrans = TRUE;
@@ -778,90 +789,92 @@
         bImage = FALSE;
     }
     if ((pimldp->fStyle & ILD_TRANSPARENT) && (himlLocal->hbmMask))
+    {
         bMaskTrans = TRUE;
+        bImageTrans = TRUE;
+    }
     if ((himlLocal->clrBk == CLR_NONE) && (himlLocal->hbmMask))
         bMaskTrans = TRUE;
 
-
-    if ((pimldp->fStyle & ILD_BLEND25) || (pimldp->fStyle & ILD_BLEND50))
-        bBlend = TRUE;
+    if (pimldp->fStyle & ILD_BLEND50)
+        bBlend50 = TRUE;
+    else if (pimldp->fStyle & ILD_BLEND25)
+        bBlend25 = TRUE;
 
     hdcImageList = CreateCompatibleDC32 (0);
 
-
     if (bMask)
     {
         /* draw the mask */
         SelectObject32 (hdcImageList, himlLocal->hbmMask);
         
-        BitBlt32 (pimldp->hdcDst, pimldp->x, pimldp->y, pimldp->himl->cx,
-                  pimldp->himl->cy, hdcImageList,
-                  pimldp->himl->cx * pimldp->i, 0,
+        BitBlt32 (pimldp->hdcDst, pimldp->x, pimldp->y,
+                  himlLocal->cx, himlLocal->cy, hdcImageList,
+                  himlLocal->cx * pimldp->i, 0,
                   bMaskTrans ? SRCAND : SRCCOPY);
     }
+
     if (bImage)
     {
         /* draw the image */
         SelectObject32 (hdcImageList, himlLocal->hbmImage);
-        if (!bBlend)
+
+        if (!bImageTrans)
         {
-            if (!bImageTrans)
-            {
-                hBrush = CreateSolidBrush32 (himlLocal->clrBk);
-                hOldBrush = SelectObject32 (pimldp->hdcDst, hBrush);
-                PatBlt32 (pimldp->hdcDst, pimldp->x, pimldp->y,
-                          himlLocal->cx, himlLocal->cy, PATCOPY);
-                DeleteObject32 (SelectObject32 (pimldp->hdcDst, hOldBrush));
-            }
-            BitBlt32 (pimldp->hdcDst, pimldp->x, pimldp->y, himlLocal->cx,
-                      himlLocal->cy, hdcImageList, himlLocal->cx * pimldp->i, 0,
-                      SRCPAINT);
+            hBrush = CreateSolidBrush32 (himlLocal->clrBk);
+            hOldBrush = SelectObject32 (pimldp->hdcDst, hBrush);
+            PatBlt32 (pimldp->hdcDst, pimldp->x, pimldp->y,
+                      himlLocal->cx, himlLocal->cy, PATCOPY);
+            DeleteObject32 (SelectObject32 (pimldp->hdcDst, hOldBrush));
         }
-        else
+
+        BitBlt32 (pimldp->hdcDst, pimldp->x, pimldp->y, himlLocal->cx,
+                  himlLocal->cy, hdcImageList, himlLocal->cx * pimldp->i, 0,
+                  SRCPAINT);
+
+        if (bBlend25 || bBlend50)
         {
             if (pimldp->rgbFg == CLR_DEFAULT)
-                clrBlend = (GetSysColor32 (COLOR_HIGHLIGHT) & 0xFEFEFEFE)>>1;
+                clrBlend = GetSysColor32 (COLOR_HIGHLIGHT);
             else
-                clrBlend = (pimldp->rgbFg & 0xFEFEFEFE)>>1;
+                clrBlend = pimldp->rgbFg;
 
             hdcTempImage = CreateCompatibleDC32 (0);
             hbmTempImage = CreateBitmap32 (himlLocal->cx, himlLocal->cy,
                                            1, himlLocal->uBitsPixel, NULL);
             SelectObject32 (hdcTempImage, hbmTempImage);
-            PatBlt32 (hdcTempImage, 0, 0, himlLocal->cx, himlLocal->cy, BLACKNESS);
 
-#if 0
-            if (bImageTrans)
-            {
-#endif
-                hdcMask = CreateCompatibleDC32 (0);           
-                SelectObject32 (hdcMask, himlLocal->hbmMask);
-                nStartX = pimldp->i * himlLocal->cx;
 
-                for (nRunY = 0; nRunY < himlLocal->cy; nRunY++)
-                {
-                    for (nRunX = 0; nRunX < himlLocal->cx; nRunX++)
-                    {
-                        if (GetPixel32 (hdcMask, nStartX + nRunX, nRunY) == 0)
-                        {
-                            clrImage = GetPixel32 (hdcImageList, nStartX + nRunX, nRunY);
-                            clrImage = ((clrImage & 0xFEFEFEFE)>>1) + clrBlend;
+            /* mask */
+            SelectObject32 (hdcTempImage,
+                            bBlend50 ? himlLocal->hbrBlend50 : himlLocal->hbrBlend25);
+            PatBlt32 (hdcTempImage, 0, 0, himlLocal->cx, himlLocal->cy, PATCOPY);
 
-                            SetPixel32 (hdcTempImage, nRunX, nRunY, clrImage);
-                        }
-                    }
-                }
+            SelectObject32 (hdcImageList, himlLocal->hbmMask);
+            BitBlt32 (hdcTempImage, 0, 0, himlLocal->cx,
+                      himlLocal->cy, hdcImageList, 
+                      pimldp->i * himlLocal->cx, 0, SRCPAINT);
 
-                DeleteDC32 (hdcMask);
-                BitBlt32 (pimldp->hdcDst, pimldp->x, pimldp->y, himlLocal->cx,
-                          himlLocal->cy, hdcTempImage, 0, 0, SRCPAINT);
-#if 0
-            }
-            else
-            {
+            BitBlt32 (pimldp->hdcDst, pimldp->x, pimldp->y, himlLocal->cx,
+                      himlLocal->cy, hdcTempImage, 0, 0, SRCAND);
 
-            }
-#endif
+            /* fill */
+            hBrush = CreateSolidBrush32 (clrBlend);
+            SelectObject32 (hdcTempImage, hBrush);
+            PatBlt32 (hdcTempImage, 0, 0, himlLocal->cx, himlLocal->cy, PATCOPY);
+            DeleteObject32 (hBrush);
+
+            SelectObject32 (hdcTempImage,
+                            bBlend50 ? himlLocal->hbrBlend50 : himlLocal->hbrBlend25);
+            PatBlt32 (hdcTempImage, 0, 0, himlLocal->cx, himlLocal->cy, 0x0A0329);
+
+            SelectObject32 (hdcImageList, himlLocal->hbmMask);
+            BitBlt32 (hdcTempImage, 0, 0, himlLocal->cx,
+                      himlLocal->cy, hdcImageList, 
+                      pimldp->i * himlLocal->cx, 0, SRCPAINT);
+
+            BitBlt32 (pimldp->hdcDst, pimldp->x, pimldp->y, himlLocal->cx,
+                      himlLocal->cy, hdcTempImage, 0, 0, SRCPAINT);
 
             DeleteObject32 (hbmTempImage);
             DeleteDC32 (hdcTempImage);
@@ -946,6 +959,15 @@
 }
 
 
+/*************************************************************************
+ *	 		 ImageList_EndDrag   [COMCTL32.54]
+ *
+ *  Finishes a drag operation.
+ *
+ *  FIXME
+ *    semi-stub.
+ */
+
 BOOL32 WINAPI ImageList_EndDrag (VOID)
 {
     FIXME (imagelist, "partially implemented!\n");
@@ -965,6 +987,15 @@
 }
 
 
+/*************************************************************************
+ *	 		 ImageList_GetBkColor   [COMCTL32.55]
+ *
+ *  Returns the background color of an image list.
+ *
+ *  RETURNS
+ *    Background color.
+ */
+
 COLORREF WINAPI ImageList_GetBkColor (
 	HIMAGELIST himl)
 {
@@ -972,6 +1003,15 @@
 }
 
 
+/*************************************************************************
+ *	 		 ImageList_GetDragImage   [COMCTL32.56]
+ *
+ *  Returns the handle to the internal drag image list.
+ *
+ *  FIXME
+ *    semi-stub.
+ */
+
 HIMAGELIST WINAPI ImageList_GetDragImage (
 	POINT32 *ppt,
 	POINT32 *pptHotspot)
@@ -985,6 +1025,10 @@
 }
 
 
+/*************************************************************************
+ *	 		 ImageList_GetIcon   [COMCTL32.57]
+ */
+
 HICON32 WINAPI ImageList_GetIcon (
 	HIMAGELIST himl, 
 	INT32 i, 
@@ -1002,8 +1046,7 @@
     ii.xHotspot = 0;
     ii.yHotspot = 0;
     ii.hbmMask  = CreateBitmap32 (nWidth, nHeight, 1, 1, NULL);
-    ii.hbmColor = CreateBitmap32 (nWidth, nHeight,
-                                  1, 1, NULL);
+    ii.hbmColor = CreateBitmap32 (nWidth, nHeight, 1, 1, NULL);
 
     hdc = CreateCompatibleDC32(0);
 
@@ -1027,6 +1070,10 @@
 }
 
 
+/*************************************************************************
+ *	 		 ImageList_GetIconSize   [COMCTL32.58]
+ */
+
 BOOL32 WINAPI ImageList_GetIconSize (
 	HIMAGELIST himl,
 	INT32 *cx,
@@ -1044,6 +1091,10 @@
 }
 
 
+/*************************************************************************
+ *	 		 ImageList_GetIconCount   [COMCTL32.59]
+ */
+
 INT32 WINAPI ImageList_GetImageCount (
 	HIMAGELIST himl)
 {
@@ -1051,6 +1102,10 @@
 }
 
 
+/*************************************************************************
+ *	 		 ImageList_GetImageInfo   [COMCTL32.60]
+ */
+
 BOOL32 WINAPI ImageList_GetImageInfo (
 	HIMAGELIST himl,
 	INT32 i,
@@ -1070,7 +1125,12 @@
 }
 
 
-/* I don't know if it is really a BOOL32 or something else!!!?? */
+/*************************************************************************
+ *	 		 ImageList_GetImageRect   [COMCTL32.61]
+ *
+ *  COMMENTS
+ *    I don't know if it really returns a BOOL32 or something else!!!??
+ */
 
 BOOL32 WINAPI ImageList_GetImageRect (
 	HIMAGELIST himl,
@@ -1090,6 +1150,10 @@
 }
 
 
+/*************************************************************************
+ *	 		 ImageList_LoadImage32A   [COMCTL32.63]
+ */
+
 HIMAGELIST WINAPI ImageList_LoadImage32A (
 	HINSTANCE32 hi,
 	LPCSTR lpbmp,
@@ -1152,6 +1216,10 @@
 }
 
 
+/*************************************************************************
+ *	 		 ImageList_LoadImage32W   [COMCTL32.64]
+ */
+
 HIMAGELIST WINAPI ImageList_LoadImage32W (
 	HINSTANCE32 hi,
 	LPCWSTR lpbmp,
@@ -1217,6 +1285,10 @@
 }
 
 
+/*************************************************************************
+ *	 		 ImageList_Merge   [COMCTL32.65]
+ */
+
 HIMAGELIST WINAPI ImageList_Merge (
 	HIMAGELIST himl1,
 	INT32 i1,
@@ -1234,7 +1306,15 @@
     if ((himl1 == NULL) || (himl2 == NULL)) return (NULL);
 
     /* check indices */
+    if ((i1 < 0) || (i1 >= himl1->cCurImage)) {
+        ERR (imagelist, "Index 1 out of range! %d\n", i1);
+        return (NULL);
+    }
 
+    if ((i2 < 0) || (i2 >= himl2->cCurImage)) {
+        ERR (imagelist, "Index 2 out of range! %d\n", i2);
+        return (NULL);
+    }
 
     if (xOffs > 0) {
         cxDst = _MAX (himl1->cx, xOffs + himl2->cx);
@@ -1435,9 +1515,6 @@
 
         himl->cCurImage--;
         himl->cMaxImage = himl->cCurImage + himl->cGrow;
-
-        TRACE (imagelist, "Number of images: %d\n", himl->cCurImage);
-        TRACE (imagelist, "Max. number of images: %d\n", himl->cMaxImage);
     }
 
     return (TRUE);
@@ -1507,6 +1584,7 @@
     BITMAP32 bmp;
 #endif
 
+    if (himl == NULL) return (-1);
     if ((i >= himl->cCurImage) || (i < -1)) return (-1);
 
 #ifdef __GET_ICON_INFO_HACK__
@@ -1525,8 +1603,9 @@
     if (i == -1) {
         if (himl->cCurImage + 1 >= himl->cMaxImage)
             IMAGELIST_InternalGrowBitmaps (himl, 1);
+
         nIndex = himl->cCurImage;
-        himl->cCurImage ++;
+        himl->cCurImage++;
     }
     else
         nIndex = i;
@@ -1645,24 +1724,25 @@
 {
     HDC32     hdcImageList, hdcBitmap;
     HBITMAP32 hbmNewBitmap;
-    INT32     nNewWidth;
+    INT32     nNewCount, nCopyCount;
 
     if (himl == NULL) return (FALSE);
     if (himl->cCurImage <= iImageCount) return (FALSE);
     if (himl->cMaxImage > iImageCount) return (TRUE);
 
-    nNewWidth = (iImageCount + himl->cGrow) * himl->cx;
+    nNewCount = iImageCount + himl->cGrow;
+    nCopyCount = _MIN(himl->cCurImage, iImageCount);
 
     hdcImageList = CreateCompatibleDC32 (0);
     hdcBitmap = CreateCompatibleDC32 (0);
 
-    hbmNewBitmap =
-        CreateBitmap32 (nNewWidth, himl->cy, 1, himl->uBitsPixel, NULL);
+    hbmNewBitmap = CreateBitmap32 (nNewCount * himl->cx, himl->cy,
+                                   1, himl->uBitsPixel, NULL);
     if (hbmNewBitmap == 0)
     {
         SelectObject32 (hdcImageList, himl->hbmImage);
         SelectObject32 (hdcBitmap, hbmNewBitmap);
-        BitBlt32 (hdcBitmap, 0, 0, himl->cCurImage * himl->cx, himl->cy,
+        BitBlt32 (hdcBitmap, 0, 0, nCopyCount * himl->cx, himl->cy,
                   hdcImageList, 0, 0, SRCCOPY);
         DeleteObject32 (himl->hbmImage);
         himl->hbmImage = hbmNewBitmap;
@@ -1674,14 +1754,13 @@
 
     if (himl->hbmMask)
     {
-        hbmNewBitmap = 
-            CreateBitmap32 (nNewWidth, himl->cy, 1, 1, NULL);
-
+        hbmNewBitmap = CreateBitmap32 (nNewCount * himl->cx, himl->cy,
+                                       1, 1, NULL);
         if (hbmNewBitmap != 0)
         {
             SelectObject32 (hdcImageList, himl->hbmMask);
             SelectObject32 (hdcBitmap, hbmNewBitmap);
-            BitBlt32 (hdcBitmap, 0, 0, himl->cCurImage * himl->cx, himl->cy,
+            BitBlt32 (hdcBitmap, 0, 0, nCopyCount * himl->cx, himl->cy,
                       hdcImageList, 0, 0, SRCCOPY);
             DeleteObject32 (himl->hbmMask);
             himl->hbmMask = hbmNewBitmap;
@@ -1695,8 +1774,10 @@
     DeleteDC32 (hdcImageList);
     DeleteDC32 (hdcBitmap);
 
-    /* Update max image count */
-    himl->cMaxImage = iImageCount + himl->cx;
+    /* Update max image count and current image count */
+    himl->cMaxImage = nNewCount;
+    if (himl->cCurImage > nCopyCount)
+        himl->cCurImage = nCopyCount;
 
     return (TRUE);
 }