There are a few problems with your code.
Firstly, when you create a new DC it starts out with a monochrome bitmap in it, so your CreateCompatibleBitmap
call will also produce a monochrome one. Instead, you probably want to create the bitmap based on the window or screen DC.
Secondly, you never actually select the bitmap into dcDest
, so nothing will be drawn into hIcon
anyway.
Thirdly, ImageList_Add
will fail if the bitmap is currently selected into a device context, so you have to deselect hIcon
from dcDest
before you add the icon to the image list.
Lastly, you are also neglecting to save the original bitmaps and restore them, so this will also cause a GDI leak.
Try something like this:
HDC hdcWindow = GetDC(hWnd);
HDC dcDest = CreateCompatibleDC(hDCWindow);
HBITMAP hIcon = CreateCompatibleBitmap(hDCWindow, cx, cy);
HDC dcSrc = CreateCompatibleDC(NULL);
HGDIOBJ hOldSourceBmp = SelectObject(dcSrc, hSkin);
HGDIOBJ hOldDestBmp = SelectObject(dcDest, hIcon);
BitBlt(dcDest, 0, 0, cx, cy, dcSrc, x, y, SRCCOPY);
SelectObject(dcDest, hOldDestBmp);
SelectObject(dcSrc, hOldSourceBmp);
*pIcon = ImageList_Add(m_hImageList, hIcon, NULL);
DeleteObject(hIcon);
DeleteDC(dcSrc);
DeleteDC(dcDest);
ReleaseDC(hWnd, hDCWindow);