HICON MergeIcon (HICON iconlg, HICON iconsm, int width, int height)
{
HDC hdc = GetDC(NULL);
HBITMAP colorbmp, oldbmp;
//生成color位图
HDC tempdc = ::CreateCompatibleDC(NULL);
colorbmp = CreateCompatibleBitmap(hdc, width, height);
oldbmp = (HBITMAP)SelectObject(tempdc, colorbmp);
HBRUSH hr = CreateSolidBrush(0);
RECT rc;
rc.left = 0;
rc.top = 0;
rc.right = width;
rc.bottom = height;
FillRect(tempdc, &rc, hr);
DrawIcon(tempdc, 0, 0, iconlg);
DrawIcon(tempdc, 0, 0, iconsm);
//保存color位图
colorbmp = (HBITMAP)SelectObject(tempdc, oldbmp);
/**///////////////////////////////////////////////////////////////////////////
//生成mask位图
HDC maskdc = ::CreateCompatibleDC(NULL);
HBITMAP maskbmp = CreateCompatibleBitmap(maskdc, width, height);
oldbmp = (HBITMAP)SelectObject(maskdc, maskbmp);
hr = CreateSolidBrush(0xffffff);
FillRect(maskdc, &rc, hr);
DrawIcon(maskdc, 0, 0, iconlg);
DrawIcon(maskdc, 0, 0, iconsm);
//保存mask位图
maskbmp = (HBITMAP)SelectObject(maskdc, oldbmp);
//方法一:
HIMAGELIST ImageList = ImageList_Create(width, height, ILC_MASK|ILC_COLORDDB, 1, 0);
//将画好的BMP存入image list
ImageList_Add(ImageList, colorbmp, maskbmp);
//从image list中获取Icon
return ImageList_ExtractIcon(0, ImageList, 0);
//方法二:
ICONINFO info;
info.fIcon = true;
info.hbmMask = maskbmp;
info.hbmColor = colorbmp;
return CreateIconIndirect(&info);
}