Ignore:
Timestamp:
May 15, 2003, 4:25:14 PM (22 years ago)
Author:
sandervl
Message:

Wine resync

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/comctl32/imagelist.c

    r9424 r10097  
    2727 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
    2828 *
    29  * Unless otherwise noted, we belive this code to be complete, as per
     29 * Unless otherwise noted, we believe this code to be complete, as per
    3030 * the specification mentioned above.
    3131 * If you discover missing features, or bugs, please note them below.
     
    4646#include "winerror.h"
    4747#include "winbase.h"
    48 #include "wine/obj_base.h"
    49 #include "wine/obj_storage.h"
     48#include "objbase.h"
    5049#include "commctrl.h"
    5150#include "imagelist.h"
     
    7877
    7978
     79static inline BOOL is_valid(HIMAGELIST himl)
     80{
     81    return himl && himl->magic == IMAGELIST_MAGIC;
     82}
     83
    8084
    8185/*************************************************************************
     
    97101IMAGELIST_InternalExpandBitmaps (HIMAGELIST himl, INT nImageCount, INT cx, INT cy)
    98102{
    99     HDC     hdcImageList, hdcBitmap;
    100     HBITMAP hbmNewBitmap;
     103    HDC     hdcBitmap;
     104    HBITMAP hbmNewBitmap, hbmNull;
    101105    INT     nNewWidth, nNewCount;
    102106
     
    110114
    111115    TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl, nNewWidth, cy, nNewCount);
    112     hdcImageList = CreateCompatibleDC (0);
    113116    hdcBitmap = CreateCompatibleDC (0);
    114117
     
    118121        ERR("creating new image bitmap (x=%d y=%d)!\n", nNewWidth, cy);
    119122
    120     SelectObject (hdcImageList, himl->hbmImage);
    121     SelectObject (hdcBitmap, hbmNewBitmap);
     123    hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
    122124    BitBlt (hdcBitmap, 0, 0, himl->cCurImage * himl->cx, cy,
    123               hdcImageList, 0, 0, SRCCOPY);
    124 
     125              himl->hdcImage, 0, 0, SRCCOPY);
     126
     127    SelectObject (hdcBitmap, hbmNull);
     128    SelectObject (himl->hdcImage, hbmNewBitmap);
    125129    DeleteObject (himl->hbmImage);
    126130    himl->hbmImage = hbmNewBitmap;
     
    133137            ERR("creating new mask bitmap!\n");
    134138
    135         SelectObject (hdcImageList, himl->hbmMask);
    136139        SelectObject (hdcBitmap, hbmNewBitmap);
    137140        BitBlt (hdcBitmap, 0, 0, himl->cCurImage * himl->cx, cy,
    138                   hdcImageList, 0, 0, SRCCOPY);
     141                  himl->hdcMask, 0, 0, SRCCOPY);
     142        SelectObject (hdcBitmap, hbmNull);
     143        SelectObject (himl->hdcMask, hbmNewBitmap);
    139144        DeleteObject (himl->hbmMask);
    140145        himl->hbmMask = hbmNewBitmap;
     
    143148    himl->cMaxImage = nNewCount;
    144149
    145     DeleteDC (hdcImageList);
    146150    DeleteDC (hdcBitmap);
    147151}
     
    166170ImageList_Add (HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask)
    167171{
    168     HDC     hdcImage, hdcBitmap;
     172    HDC     hdcBitmap;
    169173    INT     nFirstIndex, nImageCount;
    170174    INT     nStartX;
    171175    BITMAP  bmp;
    172     HBITMAP hOldBitmapImage, hOldBitmap;
     176    HBITMAP hOldBitmap;
    173177
    174178    TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl, hbmImage, hbmMask);
    175     if (!himl || !hbmImage)
     179    if (!is_valid(himl))
    176180        return -1;
    177181
     
    183187    nStartX = himl->cCurImage * himl->cx;
    184188
    185     hdcImage  = CreateCompatibleDC(0);
    186189    hdcBitmap = CreateCompatibleDC(0);
    187190
    188     hOldBitmapImage = SelectObject(hdcImage, himl->hbmImage);
    189191    hOldBitmap = SelectObject(hdcBitmap, hbmImage);
    190192
    191193    /* Copy result to the imagelist
    192194    */
    193     BitBlt (hdcImage, nStartX, 0, bmp.bmWidth, bmp.bmHeight,
     195    BitBlt (himl->hdcImage, nStartX, 0, bmp.bmWidth, bmp.bmHeight,
    194196        hdcBitmap, 0, 0, SRCCOPY);
    195197
    196198    if(himl->hbmMask)
    197199    {
    198         HDC hdcMask, hdcTemp;
    199         HBITMAP hOldBitmapMask, hOldBitmapTemp;
    200 
    201         hdcMask   = CreateCompatibleDC (0);
     200        HDC hdcTemp;
     201        HBITMAP hOldBitmapTemp;
     202
    202203        hdcTemp   = CreateCompatibleDC(0);
    203         hOldBitmapMask = SelectObject(hdcMask, himl->hbmMask);
    204204        hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
    205205
    206         BitBlt (hdcMask,
     206        BitBlt (himl->hdcMask,
    207207            nStartX, 0, bmp.bmWidth, bmp.bmHeight,
    208208            hdcTemp,
     
    215215        /* Remove the background from the image
    216216        */
    217         BitBlt (hdcImage,
     217        BitBlt (himl->hdcImage,
    218218            nStartX, 0, bmp.bmWidth, bmp.bmHeight,
    219             hdcMask,
     219            himl->hdcMask,
    220220            nStartX, 0,
    221221            0x220326); /* NOTSRCAND */
    222 
    223         SelectObject(hdcMask, hOldBitmapMask);
    224         DeleteDC(hdcMask);
    225     }
    226 
    227     SelectObject(hdcImage, hOldBitmapImage);
     222    }
     223
    228224    SelectObject(hdcBitmap, hOldBitmap);
    229     DeleteDC(hdcImage);
    230225    DeleteDC(hdcBitmap);
    231226
     
    250245 *     Failure: -1
    251246 */
    252 
    253 INT WINAPI
    254 ImageList_AddIcon (HIMAGELIST himl, HICON hIcon)
     247#undef ImageList_AddIcon
     248INT WINAPI ImageList_AddIcon (HIMAGELIST himl, HICON hIcon)
    255249{
    256250    return ImageList_ReplaceIcon (himl, -1, hIcon);
     
    277271ImageList_AddMasked (HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
    278272{
    279     HDC    hdcImage, hdcMask, hdcBitmap;
     273    HDC    hdcMask, hdcBitmap;
    280274    INT    nIndex, nImageCount, nMaskXOffset=0;
    281275    BITMAP bmp;
    282     HBITMAP hOldBitmap, hOldBitmapMask, hOldBitmapImage;
     276    HBITMAP hOldBitmap;
    283277    HBITMAP hMaskBitmap=0;
    284278    COLORREF bkColor;
    285279
    286280    TRACE("himl=%p hbitmap=%p clrmask=%lx\n", himl, hBitmap, clrMask);
    287     if (himl == NULL)
     281    if (!is_valid(himl))
    288282        return -1;
    289283
     
    298292    himl->cCurImage += nImageCount;
    299293
    300     hdcMask   = CreateCompatibleDC (0);
    301     hdcImage  = CreateCompatibleDC(0);
    302294    hdcBitmap = CreateCompatibleDC(0);
    303295
    304296
    305     hOldBitmapImage = SelectObject(hdcImage, himl->hbmImage);
    306297    hOldBitmap = SelectObject(hdcBitmap, hBitmap);
    307298    if(himl->hbmMask)
    308299    {
    309         hOldBitmapMask = SelectObject(hdcMask, himl->hbmMask);
     300        hdcMask = himl->hdcMask;
    310301        nMaskXOffset = nIndex * himl->cx;
    311302    }
     
    316307            the Image (Windows does this even if there is no mask)
    317308        */
     309        hdcMask = CreateCompatibleDC(0);
    318310        hMaskBitmap = CreateBitmap(bmp.bmWidth, bmp.bmHeight, 1, 1, NULL);
    319         hOldBitmapMask = SelectObject(hdcMask, hMaskBitmap);
     311        SelectObject(hdcMask, hMaskBitmap);
    320312        nMaskXOffset = 0;
    321313    }
     
    348340    /* Copy result to the imagelist
    349341    */
    350     BitBlt (hdcImage,
     342    BitBlt (himl->hdcImage,
    351343        nIndex * himl->cx, 0, bmp.bmWidth, bmp.bmHeight,
    352344        hdcBitmap,
     
    355347    /* Clean up
    356348    */
    357     SelectObject(hdcMask,hOldBitmapMask);
    358     SelectObject(hdcImage, hOldBitmapImage);
    359349    SelectObject(hdcBitmap, hOldBitmap);
    360     DeleteDC(hdcMask);
    361     DeleteDC(hdcImage);
    362350    DeleteDC(hdcBitmap);
    363351    if(!himl->hbmMask)
    364352    {
    365353        DeleteObject(hMaskBitmap);
     354        DeleteDC(hdcMask);
    366355    }
    367356
     
    391380                     INT dxHotspot, INT dyHotspot)
    392381{
    393     HDC hdcSrc, hdcDst;
    394382    INT cx, cy;
    395383
     
    397385          dxHotspot, dyHotspot);
    398386
    399     if (himlTrack == NULL)
     387    if (!is_valid(himlTrack))
    400388        return FALSE;
    401389
     
    415403    InternalDrag.dyHotspot = dyHotspot;
    416404
    417     hdcSrc = CreateCompatibleDC (0);
    418     hdcDst = CreateCompatibleDC (0);
    419 
    420405    /* copy image */
    421     SelectObject (hdcSrc, himlTrack->hbmImage);
    422     SelectObject (hdcDst, InternalDrag.himl->hbmImage);
    423     BitBlt (hdcDst, 0, 0, cx, cy, hdcSrc, iTrack * cx, 0, SRCCOPY);
     406    BitBlt (InternalDrag.himl->hdcImage, 0, 0, cx, cy, himlTrack->hdcImage, iTrack * cx, 0, SRCCOPY);
    424407
    425408    /* copy mask */
    426     SelectObject (hdcSrc, himlTrack->hbmMask);
    427     SelectObject (hdcDst, InternalDrag.himl->hbmMask);
    428     BitBlt (hdcDst, 0, 0, cx, cy, hdcSrc, iTrack * cx, 0, SRCCOPY);
    429 
    430     DeleteDC (hdcSrc);
    431     DeleteDC (hdcDst);
     409    BitBlt (InternalDrag.himl->hdcMask, 0, 0, cx, cy, himlTrack->hdcMask, iTrack * cx, 0, SRCCOPY);
    432410
    433411    InternalDrag.himl->cCurImage = 1;
     
    465443                INT iSrc, INT uFlags)
    466444{
    467     HDC hdcSrc, hdcDst;
    468 
    469445    TRACE("iDst=%d  iSrc=%d\n", iDst, iSrc);
    470446
    471     if ((himlSrc == NULL) || (himlDst == NULL))
     447    if (!is_valid(himlSrc) || !is_valid(himlDst))
    472448        return FALSE;
    473449    if ((iDst < 0) || (iDst >= himlDst->cCurImage))
     
    476452        return FALSE;
    477453
    478     hdcSrc = CreateCompatibleDC (0);
    479     if (himlDst == himlSrc)
    480         hdcDst = hdcSrc;
    481     else
    482         hdcDst = CreateCompatibleDC (0);
    483 
    484454    if (uFlags & ILCF_SWAP) {
    485455        /* swap */
     456        HDC     hdcBmp;
    486457        HBITMAP hbmTempImage, hbmTempMask;
    487458
     459        hdcBmp = CreateCompatibleDC (0);
     460       
    488461        /* create temporary bitmaps */
    489462        hbmTempImage = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
     
    494467        /* copy (and stretch) destination to temporary bitmaps.(save) */
    495468        /* image */
    496         SelectObject (hdcSrc, himlDst->hbmImage);
    497         SelectObject (hdcDst, hbmTempImage);
    498         StretchBlt (hdcDst, 0, 0, himlSrc->cx, himlSrc->cy,
    499                       hdcSrc, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
     469        SelectObject (hdcBmp, hbmTempImage);
     470        StretchBlt   (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
     471                      himlDst->hdcImage, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
    500472                      SRCCOPY);
    501473        /* mask */
    502         SelectObject (hdcSrc, himlDst->hbmMask);
    503         SelectObject (hdcDst, hbmTempMask);
    504         StretchBlt (hdcDst, 0, 0, himlSrc->cx, himlSrc->cy,
    505                       hdcSrc, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
     474        SelectObject (hdcBmp, hbmTempMask);
     475        StretchBlt   (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
     476                      himlDst->hdcMask, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
    506477                      SRCCOPY);
    507478
    508479        /* copy (and stretch) source to destination */
    509480        /* image */
    510         SelectObject (hdcSrc, himlSrc->hbmImage);
    511         SelectObject (hdcDst, himlDst->hbmImage);
    512         StretchBlt (hdcDst, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
    513                       hdcSrc, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
     481        StretchBlt   (himlDst->hdcImage, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
     482                      himlSrc->hdcImage, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
    514483                      SRCCOPY);
    515484        /* mask */
    516         SelectObject (hdcSrc, himlSrc->hbmMask);
    517         SelectObject (hdcDst, himlDst->hbmMask);
    518         StretchBlt (hdcDst, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
    519                       hdcSrc, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
     485        StretchBlt   (himlDst->hdcMask, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
     486                      himlSrc->hdcMask, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
    520487                      SRCCOPY);
    521488
    522489        /* copy (without stretching) temporary bitmaps to source (restore) */
     490        /* mask */
     491        BitBlt       (himlSrc->hdcMask, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
     492                      hdcBmp, 0, 0, SRCCOPY);
     493
    523494        /* image */
    524         SelectObject (hdcSrc, hbmTempImage);
    525         SelectObject (hdcDst, himlSrc->hbmImage);
    526         BitBlt (hdcDst, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
    527                   hdcSrc, 0, 0, SRCCOPY);
    528         /* mask */
    529         SelectObject (hdcSrc, hbmTempMask);
    530         SelectObject (hdcDst, himlSrc->hbmMask);
    531         BitBlt (hdcDst, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
    532                   hdcSrc, 0, 0, SRCCOPY);
    533 
     495        BitBlt       (himlSrc->hdcImage, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
     496                      hdcBmp, 0, 0, SRCCOPY);
    534497        /* delete temporary bitmaps */
    535498        DeleteObject (hbmTempMask);
    536499        DeleteObject (hbmTempImage);
     500        DeleteDC(hdcBmp);
    537501    }
    538502    else {
    539503        /* copy image */
    540         SelectObject (hdcSrc, himlSrc->hbmImage);
    541         if (himlSrc == himlDst)
    542             hdcDst = hdcSrc;
    543         else
    544             SelectObject (hdcDst, himlDst->hbmImage);
    545         StretchBlt (hdcDst, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
    546                       hdcSrc, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
     504        StretchBlt   (himlDst->hdcImage, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
     505                      himlSrc->hdcImage, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
    547506                      SRCCOPY);
    548507
    549508        /* copy mask */
    550         SelectObject (hdcSrc, himlSrc->hbmMask);
    551         if (himlSrc == himlDst)
    552             hdcDst = hdcSrc;
    553         else
    554             SelectObject (hdcDst, himlDst->hbmMask);
    555         StretchBlt (hdcDst, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
    556                       hdcSrc, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
     509        StretchBlt   (himlDst->hdcMask, iDst * himlDst->cx, 0, himlDst->cx, himlDst->cy,
     510                      himlSrc->hdcMask, iSrc * himlSrc->cx, 0, himlSrc->cx, himlSrc->cy,
    557511                      SRCCOPY);
    558512    }
    559 
    560     DeleteDC (hdcSrc);
    561     if (himlSrc != himlDst)
    562         DeleteDC (hdcDst);
    563513
    564514    return TRUE;
     
    586536{
    587537    HIMAGELIST himl;
    588     HDC      hdc;
    589538    INT      nCount;
    590539    HBITMAP  hbmTemp;
     
    601550        return NULL;
    602551
     552    cGrow = (cGrow < 4) ? 4 : (cGrow + 3) & ~3;
     553
     554    himl->magic     = IMAGELIST_MAGIC;
    603555    himl->cx        = cx;
    604556    himl->cy        = cy;
     
    607559    himl->cInitial  = cInitial;
    608560    himl->cGrow     = cGrow;
    609     himl->cCurImage = 0;
    610561    himl->clrFg     = CLR_DEFAULT;
    611562    himl->clrBk     = CLR_NONE;
     
    615566        himl->nOvlIdx[nCount] = -1;
    616567
    617     hdc = CreateCompatibleDC (0);
    618     himl->uBitsPixel = (UINT)GetDeviceCaps (hdc, BITSPIXEL);
    619     DeleteDC (hdc);
     568    /* Create Image & Mask DCs */
     569    himl->hdcImage = CreateCompatibleDC (0);
     570    if (!himl->hdcImage)
     571        goto cleanup;
     572    if (himl->flags & ILC_MASK){
     573        himl->hdcMask = CreateCompatibleDC(0);
     574        if (!himl->hdcMask)
     575            goto cleanup;
     576    }
     577
     578    himl->uBitsPixel = (UINT)GetDeviceCaps (himl->hdcImage, BITSPIXEL);
    620579
    621580    TRACE("Image: %d Bits per Pixel\n", himl->uBitsPixel);
     
    627586        if (himl->hbmImage == 0) {
    628587            ERR("Error creating image bitmap!\n");
    629             return NULL;
     588            goto cleanup;
    630589        }
    631     }
    632     else
    633         himl->hbmImage = 0;
    634 
    635     if ( (himl->flags & ILC_MASK)) {
    636         int images = himl->cMaxImage;
    637         if (images <= 0)
    638             images = 1;
    639 
    640         himl->hbmMask = CreateBitmap (himl->cx * images, himl->cy,
    641                                         1, 1, NULL);
     590        SelectObject(himl->hdcImage, himl->hbmImage);
     591    }
     592
     593    if (himl->flags & ILC_MASK) {
     594        himl->hbmMask =
     595          CreateBitmap (himl->cx * himl->cMaxImage, himl->cy,
     596                        1, 1, NULL);
    642597        if (himl->hbmMask == 0) {
    643598            ERR("Error creating mask bitmap!\n");
    644             if (himl->hbmImage)
    645                 DeleteObject (himl->hbmImage);
    646             return NULL;
     599            goto cleanup;
    647600        }
    648     }
    649     else
    650         himl->hbmMask = 0;
     601        SelectObject(himl->hdcMask, himl->hbmMask);
     602    }
    651603
    652604    /* create blending brushes */
     
    661613    TRACE("created imagelist %p\n", himl);
    662614    return himl;
     615
     616cleanup:
     617    if (himl) ImageList_Destroy(himl);
     618    return NULL;
    663619}
    664620
     
    680636ImageList_Destroy (HIMAGELIST himl)
    681637{
    682     if (!himl)
     638    if (!is_valid(himl))
    683639        return FALSE;
    684640
     
    689645        DeleteObject (himl->hbmMask);
    690646
     647    /* delete image & mask DCs */
     648    if (himl->hdcImage)
     649        DeleteDC(himl->hdcImage);
     650    if (himl->hdcMask)
     651        DeleteDC(himl->hdcMask);
     652
    691653    /* delete blending brushes */
    692654    if (himl->hbrBlend25)
     
    726688    TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock, x, y);
    727689
    728     if (InternalDrag.himl == NULL)
     690    if (!is_valid(InternalDrag.himl))
    729691        return FALSE;
    730692
     
    848810    TRACE("(x=%d y=%d)\n", x, y);
    849811
    850     if (!InternalDrag.himl) {
     812    if (!is_valid(InternalDrag.himl))
    851813        return FALSE;
    852     }
    853814
    854815    /* draw/update the drag image */
     
    937898    INT x, y;
    938899
     900    if (!is_valid(InternalDrag.himl))
     901        return FALSE;
     902   
    939903    TRACE("bShow=0x%X!\n", bShow);
    940904
     
    10811045    COLORREF clrBk, oldImageBk, oldImageFg;
    10821046    HDC hImageDC, hImageListDC, hMaskListDC;
    1083     HBITMAP hImageBmp, hOldImageBmp, hOldImageListBmp, hOldMaskListBmp, hBlendMaskBmp;
     1047    HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
    10841048    BOOL bIsTransparent, bBlend, bResult = FALSE;
    10851049    HIMAGELIST himl;
    10861050
    10871051    if (!pimldp || !(himl = pimldp->himl)) return FALSE;
     1052    if (!is_valid(himl)) return FALSE;
    10881053    if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
    10891054
     
    11031068
    11041069    /* we will use these DCs to access the images and masks in the ImageList */
    1105     hImageListDC = CreateCompatibleDC(0);
    1106     hMaskListDC = himl->hbmMask ? CreateCompatibleDC(0) : 0;
     1070    hImageListDC = himl->hdcImage;
     1071    hMaskListDC  = himl->hdcMask;
    11071072
    11081073    /* these will accumulate the image and mask for the image we're drawing */
     
    11161081        goto cleanup;
    11171082   
    1118     hOldImageListBmp = SelectObject(hImageListDC, himl->hbmImage);
    11191083    hOldImageBmp = SelectObject(hImageDC, hImageBmp);
    1120     hOldMaskListBmp = hMaskListDC ? SelectObject(hMaskListDC, himl->hbmMask) : 0;
    11211084 
    11221085    /*
     
    12201183    SetTextColor(hImageDC, oldImageFg);
    12211184    SelectObject(hImageDC, hOldImageBmp);
    1222     SelectObject(hImageListDC, hOldImageListBmp);
    1223     if (hMaskListDC) SelectObject(hMaskListDC, hOldMaskListBmp);
    12241185cleanup:
    12251186    DeleteObject(hBlendMaskBmp);
    12261187    DeleteObject(hImageBmp);
    12271188    DeleteDC(hImageDC);
    1228     DeleteDC(hImageListDC);
    1229     DeleteDC(hMaskListDC);
    12301189
    12311190    return bResult;
     
    12481207{
    12491208    HIMAGELIST himlDst;
    1250     HDC hdcSrc, hdcDst;
    1251 
    1252     if (himlSrc == NULL) {
     1209
     1210    if (!is_valid(himlSrc)) {
    12531211        ERR("Invalid image list handle!\n");
    12541212        return NULL;
     
    12601218    if (himlDst)
    12611219    {
    1262         hdcSrc = CreateCompatibleDC (0);
    1263         hdcDst = CreateCompatibleDC (0);
    1264         SelectObject (hdcSrc, himlSrc->hbmImage);
    1265         SelectObject (hdcDst, himlDst->hbmImage);
    1266         BitBlt (hdcDst, 0, 0, himlSrc->cCurImage * himlSrc->cx, himlSrc->cy,
    1267                   hdcSrc, 0, 0, SRCCOPY);
     1220        BitBlt (himlDst->hdcImage, 0, 0, himlSrc->cCurImage * himlSrc->cx, himlSrc->cy,
     1221                himlSrc->hdcImage, 0, 0, SRCCOPY);
    12681222
    12691223        if (himlDst->hbmMask)
    1270         {
    1271             SelectObject (hdcSrc, himlSrc->hbmMask);
    1272             SelectObject (hdcDst, himlDst->hbmMask);
    1273             BitBlt (hdcDst, 0, 0, himlSrc->cCurImage * himlSrc->cx,
    1274                       himlSrc->cy, hdcSrc, 0, 0, SRCCOPY);
    1275         }
    1276 
    1277         DeleteDC (hdcDst);
    1278         DeleteDC (hdcSrc);
     1224            BitBlt (himlDst->hdcMask, 0, 0, himlSrc->cCurImage * himlSrc->cx, himlSrc->cy,
     1225                    himlSrc->hdcMask, 0, 0, SRCCOPY);
    12791226
    12801227        himlDst->cCurImage = himlSrc->cCurImage;
     
    13551302ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
    13561303{
    1357     if (InternalDrag.himl) {
     1304    if (is_valid(InternalDrag.himl)) {
    13581305        if (ppt) {
    13591306            ppt->x = InternalDrag.x;
     
    14091356    HDC hdcDst;
    14101357
    1411     if ((himl == NULL) || (i < 0) || (i >= himl->cCurImage)) return 0;
     1358    TRACE("%p %d %d\n", himl, i, fStyle);
     1359    if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
    14121360
    14131361    hdcDst = CreateCompatibleDC(0);
    14141362
    14151363    ii.fIcon = TRUE;
     1364    ii.xHotspot = 0;
     1365    ii.yHotspot = 0;
    14161366
    14171367    /* draw mask*/
    14181368    ii.hbmMask  = CreateCompatibleBitmap (hdcDst, himl->cx, himl->cy);
    1419     hOldDstBitmap = (HBITMAP)SelectObject (hdcDst, ii.hbmMask);
    1420     ImageList_Draw(himl, i, hdcDst, 0, 0, ILD_MASK);
     1369    hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
     1370    PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, WHITENESS);
     1371    ImageList_Draw(himl, i, hdcDst, 0, 0, fStyle | ILD_MASK);
    14211372
    14221373    /* draw image*/
    1423     SelectObject (hdcDst, himl->hbmImage);
    1424     ii.hbmColor = CreateCompatibleBitmap (hdcDst, himl->cx, himl->cy);
     1374    ii.hbmColor = CreateCompatibleBitmap (himl->hdcImage, himl->cx, himl->cy);
    14251375    SelectObject (hdcDst, ii.hbmColor);
    1426     ImageList_Draw(himl, i, hdcDst, 0, 0, fStyle);
     1376    PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
     1377    ImageList_Draw(himl, i, hdcDst, 0, 0, fStyle | ILD_TRANSPARENT);
    14271378
    14281379    /*
     
    14631414ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
    14641415{
    1465     if (himl == NULL)
     1416    if (!is_valid(himl))
    14661417        return FALSE;
    14671418    if ((himl->cx <= 0) || (himl->cy <= 0))
     
    14931444ImageList_GetImageCount (HIMAGELIST himl)
    14941445{
    1495     if (himl == NULL)
     1446    if (!is_valid(himl))
    14961447        return 0;
    14971448
     
    15181469ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
    15191470{
    1520     if ((himl == NULL) || (pImageInfo == NULL))
     1471    if (!is_valid(himl) || (pImageInfo == NULL))
    15211472        return FALSE;
    15221473    if ((i < 0) || (i >= himl->cCurImage))
     
    15561507ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
    15571508{
    1558     if ((himl == NULL) || (lpRect == NULL))
     1509    if (!is_valid(himl) || (lpRect == NULL))
    15591510        return FALSE;
    15601511    if ((i < 0) || (i >= himl->cCurImage))
     
    16271578        himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
    16281579                                 nImageCount, cGrow);
     1580        if (!himl) {
     1581            DeleteObject (handle);
     1582            return NULL;
     1583        }
    16291584        ImageList_AddMasked (himl, (HBITMAP)handle, clrMask);
    16301585    }
     
    16371592        himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
    16381593                                 ILC_MASK | ILC_COLOR, 1, cGrow);
     1594        if (!himl) {
     1595            DeleteObject (ii.hbmColor);
     1596            DeleteObject (ii.hbmMask);
     1597            DeleteObject (handle);
     1598            return NULL;
     1599        }
    16391600        ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
    16401601        DeleteObject (ii.hbmColor);
     
    17041665        himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
    17051666                                 nImageCount, cGrow);
     1667        if (!himl) {
     1668            DeleteObject (handle);
     1669            return NULL;
     1670        }
    17061671        ImageList_AddMasked (himl, (HBITMAP)handle, clrMask);
    17071672    }
     
    17111676
    17121677        GetIconInfo (handle, &ii);
    1713         GetObjectA (ii.hbmMask, sizeof(BITMAP), (LPVOID)&bmp);
     1678        GetObjectW (ii.hbmMask, sizeof(BITMAP), (LPVOID)&bmp);
    17141679        himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
    17151680                                 ILC_MASK | ILC_COLOR, 1, cGrow);
     1681        if (!himl) {
     1682            DeleteObject (ii.hbmColor);
     1683            DeleteObject (ii.hbmMask);
     1684            DeleteObject (handle);
     1685            return NULL;
     1686        }
    17161687        ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
    17171688        DeleteObject (ii.hbmColor);
     
    17491720{
    17501721    HIMAGELIST himlDst = NULL;
    1751     HDC      hdcSrcImage, hdcDstImage;
    17521722    INT      cxDst, cyDst;
    17531723    INT      xOff1, yOff1, xOff2, yOff2;
     
    17571727           i2, dx, dy);
    17581728
    1759     if ((himl1 == NULL) || (himl2 == NULL))
     1729    if (!is_valid(himl1) || !is_valid(himl2))
    17601730        return NULL;
    17611731
     
    18041774
    18051775    himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1);
     1776    if (!himlDst)
     1777        return NULL;
    18061778
    18071779    if (himlDst) {
    1808         hdcSrcImage = CreateCompatibleDC (0);
    1809         hdcDstImage = CreateCompatibleDC (0);
    18101780        nX1 = i1 * himl1->cx;
    18111781        nX2 = i2 * himl2->cx;
    18121782
    18131783        /* copy image */
    1814         SelectObject (hdcSrcImage, himl1->hbmImage);
    1815         SelectObject (hdcDstImage, himlDst->hbmImage);
    1816         BitBlt (hdcDstImage, 0, 0, cxDst, cyDst,
    1817                   hdcSrcImage, 0, 0, BLACKNESS);
    1818         BitBlt (hdcDstImage, xOff1, yOff1, himl1->cx, himl1->cy,
    1819                   hdcSrcImage, nX1, 0, SRCCOPY);
    1820 
    1821         SelectObject (hdcSrcImage, himl2->hbmMask);
    1822         BitBlt (hdcDstImage, xOff2, yOff2, himl2->cx, himl2->cy,
    1823                   hdcSrcImage, nX2, 0, SRCAND);
    1824 
    1825         SelectObject (hdcSrcImage, himl2->hbmImage);
    1826         BitBlt (hdcDstImage, xOff2, yOff2, himl2->cx, himl2->cy,
    1827                   hdcSrcImage, nX2, 0, SRCPAINT);
     1784        BitBlt (himlDst->hdcImage,     0,     0,     cxDst,     cyDst, himl1->hdcImage,   0, 0, BLACKNESS);
     1785        BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, nX1, 0, SRCCOPY);
     1786        BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , nX2, 0, SRCAND);
     1787        BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, nX2, 0, SRCPAINT);
    18281788
    18291789        /* copy mask */
    1830         SelectObject (hdcSrcImage, himl1->hbmMask);
    1831         SelectObject (hdcDstImage, himlDst->hbmMask);
    1832         BitBlt (hdcDstImage, 0, 0, cxDst, cyDst,
    1833                   hdcSrcImage, 0, 0, WHITENESS);
    1834         BitBlt (hdcDstImage, xOff1, yOff1, himl1->cx, himl1->cy,
    1835                   hdcSrcImage, nX1, 0, SRCCOPY);
    1836 
    1837         SelectObject (hdcSrcImage, himl2->hbmMask);
    1838         BitBlt (hdcDstImage, xOff2, yOff2, himl2->cx, himl2->cy,
    1839                   hdcSrcImage, nX2, 0, SRCAND);
    1840 
    1841         DeleteDC (hdcSrcImage);
    1842         DeleteDC (hdcDstImage);
     1790        BitBlt (himlDst->hdcMask,      0,     0,     cxDst,     cyDst, himl1->hdcMask,    0, 0, WHITENESS);
     1791        BitBlt (himlDst->hdcMask,  xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask,  nX1, 0, SRCCOPY);
     1792        BitBlt (himlDst->hdcMask,  xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask,  nX2, 0, SRCAND);
     1793
    18431794        himlDst->cCurImage = 1;
    18441795    }
     
    18621813/* helper for ImageList_Read, see comments below */
    18631814static HBITMAP _read_bitmap(LPSTREAM pstm,int ilcFlag,int cx,int cy) {
    1864     HDC                 xdc = 0;
     1815    HDC                        xdc = 0, hBitmapDC =0;
    18651816    BITMAPFILEHEADER    bmfh;
    18661817    BITMAPINFOHEADER    bmih;
     
    18681819    LPBITMAPINFOHEADER  bmihc = NULL;
    18691820    int                 result = 0;
    1870     HBITMAP             hbitmap = 0;
    1871     LPBYTE              bits = NULL,nbits = NULL;
    1872     int                 nbytesperline,bytesperline;
     1821    HBITMAP            hbitmap = 0, hDIB = 0;
     1822    LPBYTE             bits = NULL;
    18731823
    18741824    if (!SUCCEEDED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL))     ||
     
    19101860#endif
    19111861    {
    1912         int i,nwidth,nheight;
     1862       int i,nwidth,nheight,nRows;
    19131863
    19141864        nwidth  = width*(height/cy);
    19151865        nheight = cy;
     1866        nRows   = (height/cy);
    19161867
    19171868        if (bitsperpixel==1)
     
    19201871            hbitmap = CreateCompatibleBitmap(xdc,nwidth,nheight);
    19211872
    1922         /* Might be a bit excessive memory use here */
    1923         bits = (LPBYTE)LocalAlloc(LMEM_ZEROINIT,bmihc->biSizeImage);
    1924         nbits = (LPBYTE)LocalAlloc(LMEM_ZEROINIT,bmihc->biSizeImage);
    1925         if (!SUCCEEDED(IStream_Read ( pstm, bits, bmihc->biSizeImage, NULL)))
    1926                 goto ret1;
     1873       hDIB = CreateDIBSection(xdc,(BITMAPINFO*)bmihc,0,(LPVOID*)&bits,0,0);
     1874       if (!hDIB)
     1875           goto ret1;
     1876       if (!SUCCEEDED(IStream_Read( pstm, bits, bmihc->biSizeImage, NULL)))
     1877           goto ret1;
     1878
     1879        hBitmapDC = CreateCompatibleDC(0);
     1880        SelectObject(hBitmapDC, hbitmap);
    19271881
    19281882        /* Copy the NxM bitmap into a 1x(N*M) bitmap we need, linewise */
    19291883        /* Do not forget that windows bitmaps are bottom->top */
    1930         bytesperline    = longsperline*4;
    1931         nbytesperline   = (height/cy)*bytesperline;
    1932         for (i=0;i<height;i++) {
    1933             memcpy(
    1934                 nbits+((height-1-i)%cy)*nbytesperline+(i/cy)*bytesperline,
    1935                 bits+bytesperline*(height-1-i),
    1936                 bytesperline
    1937             );
    1938         }
    1939         bmihc->biWidth  = nwidth;
    1940         bmihc->biHeight = nheight;
    1941         if (!SetDIBits(xdc,hbitmap,0,nheight,nbits,(BITMAPINFO*)bmihc,0))
    1942                 goto ret1;
    1943         LocalFree((HLOCAL)nbits);
    1944         LocalFree((HLOCAL)bits);
     1884        TRACE("nRows=%d\n", nRows);
     1885        for (i=0; i < nRows; i++){
     1886            StretchDIBits(hBitmapDC, width*i, 0, width, cy, 0, cy*(nRows-1-i), width, cy, bits,
     1887                (BITMAPINFO*)bmihc, DIB_RGB_COLORS, SRCCOPY);
     1888        }
     1889       
    19451890        result = 1;
    19461891    }
     
    19481893    if (xdc)    ReleaseDC(0,xdc);
    19491894    if (bmihc)  LocalFree((HLOCAL)bmihc);
     1895    if (hDIB)   DeleteObject(hDIB);
     1896    if (hBitmapDC)   DeleteDC(hBitmapDC);
    19501897    if (!result) {
    19511898        if (hbitmap) {
     
    20411988        return NULL;
    20421989    }
     1990    SelectObject(himl->hdcImage, hbmColor);
     1991    DeleteObject(himl->hbmImage);
    20431992    himl->hbmImage = hbmColor;
    2044     himl->hbmMask = hbmMask;
     1993    if (hbmMask){
     1994        SelectObject(himl->hdcMask, hbmMask);
     1995        DeleteObject(himl->hbmMask);
     1996        himl->hbmMask = hbmMask;
     1997    }
    20451998    himl->cCurImage = ilHead.cCurImage;
    20461999    himl->cMaxImage = ilHead.cMaxImage;
     
    20692022{
    20702023    HBITMAP hbmNewImage, hbmNewMask;
    2071     HDC     hdcSrc, hdcDst;
     2024    HDC     hdcBmp;
    20722025    INT     cxNew, nCount;
    20732026
    20742027    TRACE("(himl=%p i=%d)\n", himl, i);
    20752028
    2076     if (himl == NULL) {
     2029    if (!is_valid(himl)) {
    20772030        ERR("Invalid image list handle!\n");
    20782031        return FALSE;
     
    20972050             himl->nOvlIdx[nCount] = -1;
    20982051
     2052        hbmNewImage = CreateBitmap (himl->cMaxImage * himl->cx, himl->cy,
     2053                            1, himl->uBitsPixel, NULL);
     2054        SelectObject (himl->hdcImage, hbmNewImage);
    20992055        DeleteObject (himl->hbmImage);
    2100         himl->hbmImage =
    2101             CreateBitmap (himl->cMaxImage * himl->cx, himl->cy,
    2102                             1, himl->uBitsPixel, NULL);
     2056        himl->hbmImage = hbmNewImage;
    21032057
    21042058        if (himl->hbmMask) {
     2059            hbmNewMask = CreateBitmap (himl->cMaxImage * himl->cx, himl->cy,
     2060                                1, 1, NULL);
     2061            SelectObject (himl->hdcMask, hbmNewMask);
    21052062            DeleteObject (himl->hbmMask);
    2106             himl->hbmMask =
    2107                 CreateBitmap (himl->cMaxImage * himl->cx, himl->cy,
    2108                                 1, 1, NULL);
     2063            himl->hbmMask = hbmNewMask;
    21092064        }
    21102065    }
     
    21292084            hbmNewMask = 0;  /* Just to keep compiler happy! */
    21302085
    2131         hdcSrc = CreateCompatibleDC (0);
    2132         hdcDst = CreateCompatibleDC (0);
     2086        hdcBmp = CreateCompatibleDC (0);
    21332087
    21342088        /* copy all images and masks prior to the "removed" image */
     
    21362090            TRACE("Pre image copy: Copy %d images\n", i);
    21372091
    2138             SelectObject (hdcSrc, himl->hbmImage);
    2139             SelectObject (hdcDst, hbmNewImage);
    2140             BitBlt (hdcDst, 0, 0, i * himl->cx, himl->cy,
    2141                       hdcSrc, 0, 0, SRCCOPY);
     2092            SelectObject (hdcBmp, hbmNewImage);
     2093            BitBlt (hdcBmp, 0, 0, i * himl->cx, himl->cy,
     2094                    himl->hdcImage, 0, 0, SRCCOPY);
    21422095
    21432096            if (himl->hbmMask) {
    2144                 SelectObject (hdcSrc, himl->hbmMask);
    2145                 SelectObject (hdcDst, hbmNewMask);
    2146                 BitBlt (hdcDst, 0, 0, i * himl->cx, himl->cy,
    2147                           hdcSrc, 0, 0, SRCCOPY);
     2097                SelectObject (hdcBmp, hbmNewMask);
     2098                BitBlt (hdcBmp, 0, 0, i * himl->cx, himl->cy,
     2099                        himl->hdcMask, 0, 0, SRCCOPY);
    21482100            }
    21492101        }
     
    21522104        if (i < himl->cCurImage - 1) {
    21532105            TRACE("Post image copy!\n");
    2154             SelectObject (hdcSrc, himl->hbmImage);
    2155             SelectObject (hdcDst, hbmNewImage);
    2156             BitBlt (hdcDst, i * himl->cx, 0, (himl->cCurImage - i - 1) * himl->cx,
    2157                       himl->cy, hdcSrc, (i + 1) * himl->cx, 0, SRCCOPY);
     2106            SelectObject (hdcBmp, hbmNewImage);
     2107            BitBlt (hdcBmp, i * himl->cx, 0, (himl->cCurImage - i - 1) * himl->cx,
     2108                      himl->cy, himl->hdcImage, (i + 1) * himl->cx, 0, SRCCOPY);
    21582109
    21592110            if (himl->hbmMask) {
    2160                 SelectObject (hdcSrc, himl->hbmMask);
    2161                 SelectObject (hdcDst, hbmNewMask);
    2162                 BitBlt (hdcDst, i * himl->cx, 0,
     2111                SelectObject (hdcBmp, hbmNewMask);
     2112                BitBlt (hdcBmp, i * himl->cx, 0,
    21632113                          (himl->cCurImage - i - 1) * himl->cx,
    2164                           himl->cy, hdcSrc, (i + 1) * himl->cx, 0, SRCCOPY);
     2114                          himl->cy, himl->hdcMask, (i + 1) * himl->cx, 0, SRCCOPY);
    21652115            }
    21662116        }
    21672117
    2168         DeleteDC (hdcSrc);
    2169         DeleteDC (hdcDst);
     2118        DeleteDC (hdcBmp);
    21702119
    21712120        /* delete old images and insert new ones */
     2121        SelectObject (himl->hdcImage, hbmNewImage);
    21722122        DeleteObject (himl->hbmImage);
    21732123        himl->hbmImage = hbmNewImage;
    21742124        if (himl->hbmMask) {
     2125            SelectObject (himl->hdcMask, hbmNewMask);
    21752126            DeleteObject (himl->hbmMask);
    21762127            himl->hbmMask = hbmNewMask;
     
    22052156                   HBITMAP hbmMask)
    22062157{
    2207     HDC hdcImageList, hdcImage;
     2158    HDC hdcImage;
    22082159    BITMAP bmp;
    22092160
    22102161    TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
    22112162
    2212     if (himl == NULL) {
     2163    if (!is_valid(himl)) {
    22132164        ERR("Invalid image list handle!\n");
    22142165        return FALSE;
     
    22202171    }
    22212172
    2222     hdcImageList = CreateCompatibleDC (0);
    22232173    hdcImage = CreateCompatibleDC (0);
    22242174    GetObjectA (hbmImage, sizeof(BITMAP), (LPVOID)&bmp);
    22252175
    22262176    /* Replace Image */
    2227     SelectObject (hdcImageList, himl->hbmImage);
    22282177    SelectObject (hdcImage, hbmImage);
    22292178
    2230     StretchBlt (hdcImageList, i * himl->cx, 0, himl->cx, himl->cy,
     2179    StretchBlt (himl->hdcImage, i * himl->cx, 0, himl->cx, himl->cy,
    22312180                  hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
    22322181
     
    22342183    {
    22352184        /* Replace Mask */
    2236         SelectObject (hdcImageList, himl->hbmMask);
    22372185        SelectObject (hdcImage, hbmMask);
    22382186
    2239         StretchBlt (hdcImageList, i * himl->cx, 0, himl->cx, himl->cy,
     2187        StretchBlt (himl->hdcMask, i * himl->cx, 0, himl->cx, himl->cy,
    22402188                      hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
    22412189
     
    22432191        /* Remove the background from the image
    22442192        */
    2245         SelectObject (hdcImageList, himl->hbmImage);
    2246         StretchBlt (hdcImageList,
     2193        StretchBlt (himl->hdcImage,
    22472194            i*himl->cx, 0, himl->cx, himl->cy,
    22482195            hdcImage,
     
    22522199
    22532200    DeleteDC (hdcImage);
    2254     DeleteDC (hdcImageList);
    22552201
    22562202    return TRUE;
     
    22762222ImageList_ReplaceIcon (HIMAGELIST himl, INT i, HICON hIcon)
    22772223{
    2278     HDC     hdcImageList, hdcImage;
     2224    HDC     hdcImage;
    22792225    INT     nIndex;
    22802226    HICON   hBestFitIcon;
    2281     HBITMAP hbmOldSrc, hbmOldDst;
     2227    HBITMAP hbmOldSrc;
    22822228    ICONINFO  ii;
    22832229    BITMAP  bmp;
     
    22852231    TRACE("(0x%lx 0x%x %p)\n", (DWORD)himl, i, hIcon);
    22862232
    2287     if (himl == NULL)
     2233    if (!is_valid(himl))
    22882234        return -1;
    22892235    if ((i >= himl->cMaxImage) || (i < -1))
     
    23122258        nIndex = i;
    23132259
    2314     hdcImageList = CreateCompatibleDC (0);
    2315     TRACE("hdcImageList=%p!\n", hdcImageList);
    2316     if (hdcImageList == 0)
    2317         ERR("invalid hdcImageList!\n");
    2318 
    23192260    hdcImage = CreateCompatibleDC (0);
    2320     TRACE("hdcImage=%p!\n", hdcImage);
     2261    TRACE("hdcImage=%p\n", hdcImage);
    23212262    if (hdcImage == 0)
    23222263        ERR("invalid hdcImage!\n");
    23232264
    2324     hbmOldDst = SelectObject (hdcImageList, himl->hbmImage);
    2325     SetTextColor( hdcImageList, RGB(0,0,0));
    2326     SetBkColor( hdcImageList, RGB(255,255,255));
     2265    SetTextColor(himl->hdcImage, RGB(0,0,0));
     2266    SetBkColor  (himl->hdcImage, RGB(255,255,255));
    23272267    hbmOldSrc = SelectObject (hdcImage, ii.hbmColor);
    2328     StretchBlt (hdcImageList, nIndex * himl->cx, 0, himl->cx, himl->cy,
     2268
     2269    StretchBlt (himl->hdcImage, nIndex * himl->cx, 0, himl->cx, himl->cy,
    23292270                  hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
    23302271
    23312272    if (himl->hbmMask) {
    2332         SelectObject (hdcImageList, himl->hbmMask);
    23332273        SelectObject (hdcImage, ii.hbmMask);
    2334         StretchBlt (hdcImageList, nIndex * himl->cx, 0, himl->cx, himl->cy,
     2274        StretchBlt   (himl->hdcMask, nIndex * himl->cx, 0, himl->cx, himl->cy,
    23352275                      hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
    23362276    }
    23372277
    23382278    SelectObject (hdcImage, hbmOldSrc);
    2339     SelectObject (hdcImageList, hbmOldDst);
    23402279
    23412280    if(hBestFitIcon)
    23422281        DestroyIcon(hBestFitIcon);
    2343     if (hdcImageList)
    2344         DeleteDC (hdcImageList);
    23452282    if (hdcImage)
    23462283        DeleteDC (hdcImage);
     
    23732310    COLORREF clrOldBk;
    23742311
    2375     if (himl == NULL)
     2312    if (!is_valid(himl))
    23762313        return CLR_NONE;
    23772314
     
    24112348    BOOL visible;
    24122349
    2413     if (InternalDrag.himl == NULL)
     2350    if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
    24142351        return FALSE;
    24152352
     
    25272464{
    25282465    INT nCount;
    2529 
    2530     if (!himl)
     2466    HBITMAP hbmNew;
     2467
     2468    if (!is_valid(himl))
    25312469        return FALSE;
    25322470
     
    25412479        himl->nOvlIdx[nCount] = -1;
    25422480
     2481    hbmNew = CreateBitmap (himl->cMaxImage * himl->cx, himl->cy,
     2482                        1, himl->uBitsPixel, NULL);
     2483    SelectObject (himl->hdcImage, hbmNew);
    25432484    DeleteObject (himl->hbmImage);
    2544     himl->hbmImage =
    2545         CreateBitmap (himl->cMaxImage * himl->cx, himl->cy,
    2546                         1, himl->uBitsPixel, NULL);
     2485    himl->hbmImage = hbmNew;
    25472486
    25482487    if (himl->hbmMask) {
     2488        hbmNew = CreateBitmap (himl->cMaxImage * himl->cx, himl->cy,
     2489                            1, 1, NULL);
     2490        SelectObject (himl->hdcMask, hbmNew);
    25492491        DeleteObject (himl->hbmMask);
    2550         himl->hbmMask =
    2551             CreateBitmap (himl->cMaxImage * himl->cx, himl->cy,
    2552                             1, 1, NULL);
     2492        himl->hbmMask = hbmNew;
    25532493    }
    25542494
     
    25742514ImageList_SetImageCount (HIMAGELIST himl, INT iImageCount)
    25752515{
    2576     HDC     hdcImageList, hdcBitmap;
     2516    HDC     hdcBitmap;
    25772517    HBITMAP hbmNewBitmap;
    25782518    INT     nNewCount, nCopyCount;
     
    25802520    TRACE("%p %d\n",himl,iImageCount);
    25812521
    2582     if (!himl)
     2522    if (!is_valid(himl))
    25832523        return FALSE;
    25842524    if (himl->cCurImage >= iImageCount)
     
    25932533    nCopyCount = min(himl->cCurImage, iImageCount);
    25942534
    2595     hdcImageList = CreateCompatibleDC (0);
    25962535    hdcBitmap = CreateCompatibleDC (0);
    25972536
     
    26002539    if (hbmNewBitmap != 0)
    26012540    {
    2602         SelectObject (hdcImageList, himl->hbmImage);
    26032541        SelectObject (hdcBitmap, hbmNewBitmap);
    26042542
    26052543        /* copy images */
    26062544        BitBlt (hdcBitmap, 0, 0, nCopyCount * himl->cx, himl->cy,
    2607                   hdcImageList, 0, 0, SRCCOPY);
     2545                himl->hdcImage, 0, 0, SRCCOPY);
    26082546#if 0
    26092547        /* delete 'empty' image space */
     
    26132551                  (nNewCount - nCopyCount) * himl->cx, himl->cy, BLACKNESS);
    26142552#endif
     2553        SelectObject (himl->hdcImage, hbmNewBitmap);
    26152554        DeleteObject (himl->hbmImage);
    26162555        himl->hbmImage = hbmNewBitmap;
     
    26252564        if (hbmNewBitmap != 0)
    26262565        {
    2627             SelectObject (hdcImageList, himl->hbmMask);
    26282566            SelectObject (hdcBitmap, hbmNewBitmap);
    26292567
    26302568            /* copy images */
    26312569            BitBlt (hdcBitmap, 0, 0, nCopyCount * himl->cx, himl->cy,
    2632                       hdcImageList, 0, 0, SRCCOPY);
     2570                    himl->hdcMask, 0, 0, SRCCOPY);
    26332571#if 0
    26342572            /* delete 'empty' image space */
     
    26382576                      (nNewCount - nCopyCount) * himl->cx, himl->cy, BLACKNESS);
    26392577#endif
     2578            SelectObject (himl->hdcMask, hbmNewBitmap);
    26402579            DeleteObject (himl->hbmMask);
    26412580            himl->hbmMask = hbmNewBitmap;
     
    26452584    }
    26462585
    2647     DeleteDC (hdcImageList);
    26482586    DeleteDC (hdcBitmap);
    26492587
     
    26742612ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
    26752613{
    2676     if (!himl)
     2614    if (!is_valid(himl))
    26772615        return FALSE;
    26782616    if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
     
    28072745    int i;
    28082746
    2809     if (!himl)
     2747    if (!is_valid(himl))
    28102748        return FALSE;
    28112749
Note: See TracChangeset for help on using the changeset viewer.