Handle CopyImage and other functions failing by not adding the icon

and notifying the caller.
This commit is contained in:
Robert Shearman 2005-07-14 10:15:59 +00:00 committed by Alexandre Julliard
parent 31acf7f5a5
commit ec167634f9

View File

@ -2226,25 +2226,51 @@ ImageList_ReplaceIcon (HIMAGELIST himl, INT i, HICON hIcon)
HBITMAP hbmOldSrc;
ICONINFO ii;
BITMAP bmp;
BOOL ret;
TRACE("(%p %d %p)\n", himl, i, hIcon);
if (!is_valid(himl))
return -1;
if ((i >= himl->cMaxImage) || (i < -1))
return -1;
if (!is_valid(himl)) {
ERR("invalid image list\n");
return -1;
}
if ((i >= himl->cMaxImage) || (i < -1)) {
ERR("invalid image index %d / %d\n", i, himl->cMaxImage);
return -1;
}
hBestFitIcon = CopyImage(
hIcon, IMAGE_ICON,
himl->cx, himl->cy,
LR_COPYFROMRESOURCE);
/* the above will fail if the icon wasn't loaded from a resource, so try
* again without LR_COPYFROMRESOURCE flag */
if (!hBestFitIcon)
hBestFitIcon = CopyImage(
hIcon, IMAGE_ICON,
himl->cx, himl->cy,
0);
if (!hBestFitIcon)
return -1;
ret = GetIconInfo (hBestFitIcon, &ii);
if (!ret) {
DestroyIcon(hBestFitIcon);
return -1;
}
GetIconInfo (hBestFitIcon, &ii);
if (ii.hbmMask == 0)
ERR("no mask!\n");
if (ii.hbmColor == 0)
ERR("no color!\n");
GetObjectA (ii.hbmMask, sizeof(BITMAP), (LPVOID)&bmp);
ret = GetObjectW (ii.hbmMask, sizeof(BITMAP), (LPVOID)&bmp);
if (!ret) {
ERR("couldn't get mask bitmap info\n");
if (ii.hbmColor)
DeleteObject (ii.hbmColor);
if (ii.hbmMask)
DeleteObject (ii.hbmMask);
DestroyIcon(hBestFitIcon);
return -1;
}
if (i == -1) {
if (himl->cCurImage + 1 > himl->cMaxImage)
@ -2276,8 +2302,7 @@ ImageList_ReplaceIcon (HIMAGELIST himl, INT i, HICON hIcon)
SelectObject (hdcImage, hbmOldSrc);
if(hBestFitIcon)
DestroyIcon(hBestFitIcon);
DestroyIcon(hBestFitIcon);
if (hdcImage)
DeleteDC (hdcImage);
if (ii.hbmColor)