Help - Search - Members - Calendar
Full Version: Custom bitmap refuses to be painted on XP (and not W2K) during dialog
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
NEMO7538
I'm trying (within my quicksearch plugin) to paint a picture control with a custom selectable bitmap. I use the following code which is called from the WM_INITDIALOG: section of my (ui extension) plugin.
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.
foosion
Have you tried adding error checks to see where it fails? The SDK also contains some helper functions to translate the code returned by GetLastError() into human-readable text. I don't remember the exact name, but they are used by exception_win32.

Also, are you trying the bitmap yourself? Is there a reason why you cannot use a static control with the image type or something that can use an image list? ImageList_LoadImage seems to be helpful for your goal.
NEMO7538
ImageList is what i tried in the first place, using a mask for transparency. But it does not support colors > 8 bpp (according to msdn, which also says LR_LOADTRANSPARENT only works with COLOR_WINDOW, which is not that I want) and in my own tests (with ImageList_AddMasked) icons appeared half greyed which is horrible. That's why i turned to brute force changing the bitmap, which works fine (on w2k and even xp, where my routine works).

I think the problem lies after/elsewhere and does not produces errors as such but rather a different handling of the sequence of events in Windows. My picture control gets grayed out after my painting for some reason I do not understand and only on XP. I have also tried to invalidate WM_ERASEBKGND with no effect.

Btw I would like to thank you as I found many examples in foo_history source code that where very usefull, but i am a bit discouraged at the moment ..... these icons where (almost) the last features i wanted to implement before porting to 0.9.
foosion
Actually, I was thinking about using ImageList_LoadImage with the crMask parameter set to CLR_DEFAULT; there is not mention of a restriction to 8bpp for this parameter as far as I can see, but I haven't tried.
NEMO7538
I gave a second try and it worked (using LR_CREATEDIBSECTION to get the right colors).

Thanks for your support.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.