Sign in to follow this  
Andrew Russell

Make a list view highlight truecolour (win32 or wxWidgets) [SOLVED]

Recommended Posts

OK, I'm using wxWidgets, but if you can tell me how to do it in win32 that would be much appreciated - I can probably find the relevent code with that info. I am doing a big refactor of some old code, and I'm using a list view as a texture browser. Now, my old code works fine, the highlight is in the true-colour style. My new code, which is almost a direct copy from the old, has a 256-colour style highlight. This is what I mean: Same image at 2x magnification: The one on the left is from the old version, the one on the right is the new version (as in - the icon, not the image - they are both the same image, increased in size for visibility). I'm using the same version of wxWidgets for both, and so I know it's not that. I vaugly remember having trouble getting it working correctly the last time around too. Unfortunatly I've left myself no comments on how it was done, and there is certianly no "Use the true-colour highlight" option that is obvious in the API. Any help is much appreciated. [Edited by - Andrew Russell on July 11, 2005 6:26:15 AM]

Share this post


Link to post
Share on other sites
It could be the color blindness, but I can't tell the difference between those two images. Is there any other way for you to describe what you want to do?

Share this post


Link to post
Share on other sites
Just to be clear the images are the same - it is the icons that are different - they are screenshots from two different programs. I'll edit the post to make it clearer.


The icon on the left is what I'm aiming for. Basically - when it is selected, it takes on a blue tint. The icon on the right is what I currently have - the selection is indicated by setting certian pixels to normal dark blue using a pattern like this:
X X X X 
X X X X
X X X X
X X X X

In other words - correct one is using a true-colour method, the other is using the method in 256-colour mode (I'm not actually sure about the number of colours actually being used - but the highlight method is the same).

Although I'm using wxWidgets - if someone knows how to change between the two in win32, I can probably work out how to do it in wxWidgets (or hack it in).


I've been working to "fix" the broken version by copying in code from the working version. The code is now, pretty much identical to the working version in all the parts that should make a difference (the creation of the list view and image list, the loading of the images, manipulation of the list, etc), yet it's still broken. So it's something very obscure. I will now try to break the working version by copying various bits of the broken code over it to see what breaks it.

Share this post


Link to post
Share on other sites
I don't know, but the new one is dithering with the selection colour, while the old one is actually blending the two. Those terms might help you to track down the solution. I've done a bit of looking, but I can't find any information on it.

Share this post


Link to post
Share on other sites
What color flags are you passing to the imagelist you use for the List Control?
I never noticed on the selection part (i usually use only report view), but i've had problems with color depths below 15/16 bit before.

Share this post


Link to post
Share on other sites
My experience has been (with Win32) that List Views and other controls use the system palette... at least in older Windows OS's...

Not that that helps... but I'm not sure a Win32 List View's highlighting can be de-coupled from the display settings... at least automatically. (Could be wrong)... XP's themes I know nothing about, however.

You may have a "custom draw" operation staring you in the face :-/

Good luck... hope your API is out there

Share this post


Link to post
Share on other sites
Well, a custom-draw operation isn't an option. And anyway - I know it can be done without one.


On the subject of what is being passed to create the image list - to wxWidgets - nothing to do with colour depth.

Looking at the source code to wxWidgets itself, the code that creates an image list goes like this:


UINT flags = 0;

int dd = wxDisplayDepth();

if (dd <= 4) flags |= ILC_COLOR; // 16 color
else if (dd <= 8) flags |= ILC_COLOR8; // 256 color
else if (dd <= 16) flags |= ILC_COLOR16; // 64k hi-color
else if (dd <= 24) flags |= ILC_COLOR24; // 16m truecolor
else if (dd <= 32) flags |= ILC_COLOR32; // 16m truecolor

m_hImageList = (WXHIMAGELIST) ImageList_Create(width, height, flags,
initial, 1);



And wxDisplayDepth() does this:
ScreenHDC dc;
return GetDeviceCaps(dc, PLANES) * GetDeviceCaps(dc, BITSPIXEL);


I will go in there with my debugger and see if the value is different.

Share this post


Link to post
Share on other sites
OK, after going through it in the debugger, both calls to ImageList_Create are exactly the same - including what depth they are created at.

I also tried using the same images to create the icons - with the same result - the old one worked, the new one didn't.

Share this post


Link to post
Share on other sites
I did the same thing for the creation of the list view itself. The values were the same here between the working and non-working version (except I didn't check "parent", "child id" or "app instance").


m_hWnd = (WXHWND)::CreateWindowEx
(
exstyle, // extended style
classname, // the kind of control to create
label, // the window name
style, // the window style
x, y, w, h, // the window position and size
GetHwndOf(GetParent()), // parent
(HMENU)GetId(), // child id
wxGetInstance(), // app instance
NULL // creation parameters
);

Share this post


Link to post
Share on other sites
One problem may be due to the ILC_COLORxx flags passed to the image list creation function. My Win32 API documentation has this to say:

Quote:
HIMAGELIST ImageList_Create(int cx, int cy, UINT flags, int cInitial, int cGrow);

Parameters

cx : Specifies the width, in pixels, of each image.

cy : Specifies the height, in pixels, of each image.

flags : A set of bit flags that specify the type of image list to create. This
parameter can be a combination of the following values, but it can include
only one of the ILC_COLOR values.

Value Meaning
ILC_COLOR Use the default behavior if none of the other ILC_COLOR* flags
is specified. Typically, the default is ILC_COLOR4; but for
older display drivers, the default is ILC_COLORDDB.
ILC_COLOR4 Use a 4-bit (16 color) device-independent bitmap (DIB) section as the bitmap for the image list.
ILC_COLOR8 Use an 8-bit DIB section. The colors used for the color table are the same colors as the halftone palette.
ILC_COLOR16 Use a 16-bit (32/64k color) DIB section.
ILC_COLOR24 Use a 24-bit DIB section.
ILC_COLOR32 Use a 32-bit DIB section.
ILC_COLORDDB Use a device-dependent bitmap.
ILC_MASK Uses a mask. The image list contains two bitmaps, one of which
is a monochrome bitmap used as a mask. If this value is not
included, the image list contains only one bitmap.

cInitial : Number of images that the image list initially contains.

cGrow : Amount of images by which the image list can grow when the system needs
to resize the list to make room for new images. This parameter represents
the number of new images that the resized image list can contain.



So it seems you can and can't use the flags in combination? I've always assumed that they mean one ILC_COLORxx value and optionally the ILC_MASK value. I usually just stick with one flag (16bits or more), and get the effects you desire. I think that if you create a list with less than 15/16bit color, you won't get the nice blended effect you're after.

arm.

EDIT: Edited for clarity.

Share this post


Link to post
Share on other sites
[SOLVED]

OK, I was just told the solution. Apparantly I needed an "XP styles manifest" in my resources. This quickly identified the difference between the two projects - the new, broken one didn't have any resource file at all.

The solution was to add one which contained the following include:
#include "wx/msw/wx.rc"
Talk about being obscure.

Thanks everyone for your help [smile]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this