CODE
static void update_picture (HWND wnd_image, int num_bitmap, int backcolor)
{
// Update picture with a background color
// The top left pixel color will be replaced with the background color
// And result will be send to the wnd_image control
// Destination
int idd_bitmap = 0;
switch(num_bitmap)
{
case 0: idd_bitmap=IDB_BITMAP; break;
case 1: idd_bitmap=IDB_BITMAP1;break;
case 2: idd_bitmap=IDB_BITMAP2;break;
case 3: idd_bitmap=IDB_BITMAP3;break;
case 4: idd_bitmap=IDB_BITMAP4;break;
case 5: idd_bitmap=IDB_BITMAP5;break;
case 6: idd_bitmap=IDB_BITMAP6;break;
case 7: idd_bitmap=IDB_BITMAP7;break;
case 8: idd_bitmap=IDB_BITMAP8;break;
case 9: idd_bitmap=IDB_BITMAP9;break;
case 10: idd_bitmap=IDC_TEST;break;
default: return;
}
bmp = (HBITMAP)uLoadImage(core_api::get_my_instance(),
MAKEINTRESOURCE(idd_bitmap), IMAGE_BITMAP, 20, 16, LR_DEFAULTCOLOR);
DestDC = ::GetDC(wnd_image);
// Source
HDC SourceDC = ::CreateCompatibleDC(DestDC);
// Associate source with bitmap
HBITMAP hOld = (HBITMAP)::SelectObject(SourceDC,bmp);
// Get bitmap info
GetObject(bmp, sizeof(bmpInfo), &bmpInfo);
//hRgn = CreateRectRgn(0,0,16,22);
DWORD dwLoopY = 0, dwLoopX = 0;
COLORREF crPixel = 0, tsPixel = 0;
tsPixel = ::GetPixel(SourceDC, 0, 0);
//Browse bitmap and replace color of the first pixel
//with our background color
for (dwLoopY = 0; dwLoopY < (DWORD)bmpInfo.bmHeight; dwLoopY++)
{
for (dwLoopX = 0; dwLoopX < (DWORD)bmpInfo.bmWidth; dwLoopX++)
{
crPixel = ::GetPixel(SourceDC, dwLoopX, dwLoopY);
if (!crPixel) continue;
if (crPixel==tsPixel)
::SetPixel(SourceDC, dwLoopX, dwLoopY, backcolor);
} // for
} // for
// Copy source to dest
::BitBlt(DestDC,0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,SourceDC,0,0,SRCCOPY);
// House keeping
::SelectObject(SourceDC,hOld);
::ReleaseDC(wnd_image,SourceDC);
//ReleaseDC(wnd_image,DestDC);
//DeleteObject(bmp);
//InvalidateRgn(wnd_image, hRgn, false);
//SetWindowRgn(wnd_image, hRgn, TRUE);
return;
}
It works like a charm in Window 2000 but refuses to work on XP. However, if it is called from elsewhere in the dialog, it works well on both platforms. Just the initialization fails on and the control is not repainted. I have also tried various options to show/refresh the control but without success. The bitmap and destination DC are defined globally.
Any thoughts .... ?
I'm fighting hard to understand what happens.
I also thought that similar code is used on the column UI buttons customization in 0.9 and could maybe shared?
Thanks for you support.