I have the following code in a CDialog. This code works perfectly on Windows 7, but its color is always black on Windows XP SP3.
UINT color_flags = CWindowDC(this).GetDeviceCaps(BITSPIXEL);
switch ( color_flags )
{
case 4 : color_flags = ILC_COLOR4; break;
case 8 : color_flags = ILC_COLOR8; break;
case 16 : color_flags = ILC_COLOR16; break;
case 24 : color_flags = ILC_COLOR24; break;
case 32 : color_flags = ILC_COLOR24; break;
default : color_flags = ILC_COLOR24;
};
CImageList imgage_list;
imgage_list.Create( 16, 16, color_flags, 0, 10 );
imgage_list.SetImageCount( number_of_bitmaps );
CDC * pDC = this->GetDC();
CDC memDC;
CRect memRect(0, 0, 16, 16);
CObject * pObj = 0;
COLORREF my_color = RGB(255,0,0);
CBitmap * bitmap = 0;
memDC.CreateCompatibleDC(pDC);
for ( int i = 0; i < number_of_bitmaps; ++i )
{
bitmap = new CBitmap;
bitmap->CreateCompatibleBitmap( pDC, 16, 16 );
pObj = memDC.SelectObject( bitmap );
memDC.FillSolidRect( memRect, my_color );
imgage_list.Replace( i, bitmap, 0 );
memDC.SelectObject(pObj);
delete bitmap;
}
memDC.DeleteDC();
this->ReleaseDC(pDC);
I enabled visual styles as it is suggested by MSDN. I use this CImageList object as a parameter of CListCtrl::SetImageList member function.
Do you have any idea?
Many thanks for help.
Final, corrected and working code:
Many thanks for help, again.