Jump to content
Tuts 4 You

Checkbox background color


starzboy

Recommended Posts

Hey ppl

I have made a checkbox on top of a bitmap image and the background of the checkbox is white, so i used SetBrushOrgEx and i have got the background transparent, but now i would like to make the text color of the checkbox to some other color, Settextcolor fails.

Is there an alternative ?

Thanx again

Link to comment

Hey ppl

I have made a checkbox on top of a bitmap image and the background of the checkbox is white, so i used SetBrushOrgEx and i have got the background transparent, but now i would like to make the text color of the checkbox to some other color, Settextcolor fails.

Is there an alternative ?

Thanx again

Hia,

Interesting question I thought to myself when I read your post. Surely it can't be very hard - well, that's what I thought at the time, anyway...

Upon further thought and searching, I couldn't remember seeing a program around that does do it, then I found DzA Patcher sitting around here. After a bit more searching, I found a couple of articles of note on Microsoft's site.

The first one mentions that after getting the transparent background to work, it screwed up when he added an XP-themes manifest file.

Here ----> [b]http://forums.msdn.microsoft.com/en-US/vcgeneral/thread/a0db67c8-3b51-4451-a636-a2737e6b3e27

About then, I noticed that DzA Patcher didn't use XP themes.

A few moments later I came across a gold nugget as M$s site. In it, it was said that you cannot change the colour of check-box text when using a manifest file, because of the way that comctl32.dll works :confused:

However, they do propose some work-arounds. You can either custom-draw the whole control OR just cheat, and have no text on the check-box control and just put a static in place to serve as the label. It still seems like a bit of a PITA, but sounds fairly light-weight and still quite manageable.

Here ----> [b]http://support.microsoft.com/kb/944311

Just get ready for a work-out if you want to put the 'currently selected control' box around the text, or indeed check/uncheck the box when the label is clicked. (Perhaps you could use a check-box label that just consisted of spaces to get around these two issues - though this leaves you with the problem of how to stop the 'currently selected control' box from covering-up your static)

Using the spaces-for-a-label idea would leave you in a world of pain as you would then have to replace the WindowFunction of the check-box, to make sure that it didn't cover-up your static label. To be honest, I'd be inclined to just make it work without XP themes..

Link to comment

You should deploy WM_CTLCOLORSTATIC message:

LOGBRUSH logTrans;

logTrans.lbStyle = BS_HOLLOW; //transparent brush

case WM_CTLCOLORSTATIC:

SetTextColor((HDC)wParam, RGB(255,0,0));

SetBkMode((HDC)wParam,TRANSPARENT);

return (int)CreateBrushIndirect(&logTrans);

//You have to return a brush, or SetTextColor wouldn't work

Link to comment
  • 1 month later...

Yup, good-old subclassing appears to be the order of the day.

I got bored and had a quick play with it again overnight. It's nothing special - the code is pretty nasty and there are some issues with flicker since I couldn't be bothered double buffering at all. It still needs to have far more messages handled - you can't even give it the keybord focus or check/uncheck it using the keyboard. I had fun anyway.

Oh and btw alaphate, you can change the background colour of the box itself on line 236 of this code.

Anyhow, if anyone wants it, it's here.

post-36039-1221864473_thumb.jpg

customCheckBox.zip

Link to comment
anbody know how to make the background of static controls transparent?

You didn't mean this one ?

[...]
.elseif uMsg==WM_CTLCOLORSTATIC
.if lParam == hSome; handle of static control
invoke SetBkMode,wParam,TRANSPARENT
invoke GetStockObject,NULL_BRUSH
ret
.endif
[...]
Link to comment

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
×
×
  • Create New...