Ticket #16 (closed defect)

Opened 9 years ago

Last modified 6 weeks ago

Toolbar tool show as gray blobs when disabled

Reported by: anonymous Owned by: vadz
Priority: normal Milestone:
Component: wxMSW Version:
Keywords: Cc: vadz
Blocked By: Patch: no
Blocking:

Description

Bug#: 66
Product: .wxWindows
Version: 2.2.0
Platform: wxMSW
OS/Version: Win 98
Status: ASSIGNED
Resolution:
Severity: major
Priority: P2
Component: samples
AssignedTo: ???
ReportedBy: wthie@…
URL:
Summary: Toolbar tool show as gray blobs when disabled in 16bit (HiColor) mode (Win2k & Win98)

The problem is NOT related to compiler NOR comctl32.dll

Compiler: MSVC 6.0 SP3

Reproducing the bug:
Take any sample with a toolbar, switch to HiColor mode under Win98 or
Win2K) and disabled tools show as gray blobs.

The problem lies in the way the toolbar bmps are created in a MemDC.
The color to be used for showing the tool disabled is reported later
on as not the same as when the tool bmp was created.

If for instance $c0c0c0 (light gray) was used when instantiating,
Windows now reports back this color as $c8c2c0, which is only
slightly off to the red, but nontheless off!

A fix I used was not testing for a specific color but a range of
colors allowed (see code below from tbar95.cpp):

// -------------------------------------------------------------------


// private functions
// -------------------------------------------------------------------


// These are the default colors used to map the bitmap colors to the
current
// system colors. Note that they are in BGR format because this is
what Windows
// wants (and not RGB)

#define BGR_BUTTONTEXT (RGB(000,000,000)) // black
#define BGR_BUTTONSHADOW (RGB(128,128,128)) // dark grey
#define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
#define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
#define BGR_BACKGROUNDSEL (RGB(000,000,255)) // blue
#define BGR_BACKGROUND (RGB(255,000,255)) // magenta

void wxMapBitmap(HBITMAP hBitmap, int width, int height)
{

COLORMAP ColorMap[] =
{

{BGR_BUTTONTEXT, COLOR_BTNTEXT}, // black
{BGR_BUTTONSHADOW, COLOR_BTNSHADOW}, // dark grey
{BGR_BUTTONFACE, COLOR_BTNFACE}, // bright grey
{BGR_BUTTONHILIGHT, COLOR_BTNHIGHLIGHT},// white
{BGR_BACKGROUNDSEL, COLOR_HIGHLIGHT}, // blue
{BGR_BACKGROUND, COLOR_WINDOW} // magenta

};

HBITMAP hbmOld;
HDC hdcMem = CreateCompatibleDC(NULL);

int NUM_MAPS = (sizeof(ColorMap)/sizeof(COLORMAP));
int n;

if (hdcMem)
{

hbmOld = (HBITMAP) SelectObject(hdcMem, hBitmap);
COLORREF save = ::GetPixel(hdcMem, 0, 0);

for ( n = 0; n < NUM_MAPS; n++)
{

ColorMap[n].from = SetPixel( hdcMem , 0 , 0 , ColorMap

[n].from ) ;

ColorMap[n].to = ::GetSysColor(ColorMap

[n].to);

}
SetPixel( hdcMem , 0 , 0 , save ) ;

int i, j, k;
for ( i = 0; i < width; i++)
{

for ( j = 0; j < height; j++)
{

COLORREF pixel = ::GetPixel(hdcMem, i, j);

for ( k = 0; k < NUM_MAPS; k ++)
{

int

distance = 0 ;



distance = abs( GetRValue( pixel ) - GetRValue( ColorMap

[k].from )) ;

distance = max( distance , abs(GetGValue( pixel ) - GetGValue

( ColorMap[k].from ))) ;

distance = max( distance , abs(GetBValue( pixel ) - GetBValue

( ColorMap[k].from ))) ;

if ( distance < 0x10 )
{

::SetPixel(hdcMem, i, j, ColorMap[k].to);
break;

}

}

}

}

SelectObject(hdcMem, hbmOld);
DeleteObject(hdcMem);

}

}

Change History

Changed 9 years ago by vadz

fixed in wxMSW 2.2.5 and in the main trunk of the cvs

Note: See TracTickets for help on using tickets.