Create bitmap

I want to create an image list from a color palette. This code compiles but the images are all black. What's wrong? tia

void CreateColorList()
{
DWORD crItems[48] =
{
RGB( 0, 0, 0), RGB( 64, 0, 0), RGB(128, 0, 0), RGB(128, 64, 64), RGB(255, 0, 0), RGB(255, 128, 128),
RGB(255, 255, 128), RGB(255, 255, 0), RGB(255, 128, 64), RGB(255, 128, 0), RGB(128, 64, 0), RGB(128, 128, 0),
RGB(128, 128, 64), RGB( 0, 64, 0), RGB( 0, 128, 0), RGB( 0, 255, 0), RGB(128, 255, 0), RGB(128, 255, 128),
RGB( 0, 255, 128), RGB( 0, 255, 64), RGB( 0, 128, 128), RGB( 0, 128, 64), RGB( 0, 64, 64), RGB(128, 128, 128),
RGB( 64, 128, 128), RGB( 0, 0, 128), RGB( 0, 0, 255), RGB( 0, 64, 128), RGB( 0, 255, 255), RGB(128, 255, 255),
RGB( 0, 128, 255), RGB( 0, 128, 192), RGB(128, 128, 255), RGB( 0, 0, 160), RGB( 0, 0, 64), RGB(192, 192, 192),
RGB( 64, 0, 64), RGB( 64, 0, 64), RGB(128, 0, 128), RGB(128, 0, 64), RGB(128, 128, 192), RGB(255, 128, 192),
RGB(255, 128, 255), RGB(255, 0, 255), RGB(255, 0, 128), RGB(128, 0, 255), RGB( 64, 0, 128), RGB(255, 255, 255),
};

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
m_pColorList = ImageList_Create(16, // width
16, // height
ILC_COLOR, // creation flags
48, // number of images
0); // amount this list can grow
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
HDC hdc = ::GetDC(m_hWnd);
HDC hdcMem = CreateCompatibleDC (hdc) ;
HBITMAP hBitmap = CreateCompatibleBitmap(hdc, 16, 16);
::ReleaseDC(m_hWnd, hdc) ;

RECT rect;
rect.bottom = 16;
rect.left = 0;
rect.right = 16;
rect.top = 0;

for(int i = 0; i < 48; i++)
{
///////////////////////////////////////////////////////////////////////////////////////////
SelectObject(hdcMem, hBitmap);
DWORD cr = crItems[i];

HBRUSH hbrush = CreateSolidBrush((COLORREF)cr);
FillRect(hdcMem, &rect, hbrush);

ImageList_Add ( m_pColorList, hBitmap, NULL);
///////////////////////////////////////////////////////////////////////////////////////////
}
DeleteDC(hdcMem);
}
[2637 byte] By [cbpetro] at [2007-11-20 10:29:16]
# 1 Re: Create bitmap
Try to play with the ILC_COLOR parameter. Try to change it to ILC_COLOR32 or something else.
Marc G at 2007-11-10 22:29:41 >
# 2 Re: Create bitmap
Mmm, on second thought, you probably need to unselect the bitmap from your DC before calling ImageList_add. Something like:
HBITMAP hOldBmp = (HBITMAP)SelectObject(hdcMem, hBitmap);
DWORD cr = crItems[i];

HBRUSH hbrush = CreateSolidBrush((COLORREF)cr);
FillRect(hdcMem, &rect, hbrush);

SelectObject(hdcMem, hOldBmp);

ImageList_Add ( m_pColorList, hBitmap, NULL);
Marc G at 2007-11-10 22:30:41 >
# 3 Re: Create bitmap
That was it.. thank you!
cbpetro at 2007-11-10 22:31:45 >
# 4 Re: Create bitmap
You're welcome :)
Marc G at 2007-11-10 22:32:50 >