BitBlt question - modifying a background color

BitBlt question - modifying a background color

Post by Gofredd » Fri, 27 Feb 1998 04:00:00



Hi.  I am trying to paint a background for a user-drawn button.  However,
this button must operate like an up-down button.  So the backcolor when the
button is down must be a lighter shade of gray.  For example, look at your
taskbar.  The currently activated app's button should be the color I am
talking about.  Or if you look at ms word, the selected alignment button
should also do it.  My problem is I don't know how to get that color.  I
don't believe it's one of the constants (all of my 3d-highlight type colors
are white, but my display shows this color as light gray.)  I need either a
way to find out this color, or maybe a way to BitBlt a mask onto a solid box
that I have already painted with vbButtonFace.  Any ideas?
-GMG

 
 
 

BitBlt question - modifying a background color

Post by Jim Deutc » Sat, 28 Feb 1998 04:00:00


The color is vb3DHighlight, AFAIK.  Works with my color scheme, anyway.
And Windows Standard (just checked).

Jim Deutch
MS Dev MVP



Quote:> Hi.  I am trying to paint a background for a user-drawn button.  However,
> this button must operate like an up-down button.  So the backcolor when
the
> button is down must be a lighter shade of gray.  For example, look at
your
> taskbar.  The currently activated app's button should be the color I am
> talking about.  Or if you look at ms word, the selected alignment button
> should also do it.  My problem is I don't know how to get that color.  I
> don't believe it's one of the constants (all of my 3d-highlight type
colors
> are white, but my display shows this color as light gray.)  I need either
a
> way to find out this color, or maybe a way to BitBlt a mask onto a solid
box
> that I have already painted with vbButtonFace.  Any ideas?
> -GMG


 
 
 

BitBlt question - modifying a background color

Post by Gofredd » Sat, 28 Feb 1998 04:00:00


Thanks Jim.  But, that one shows up as white on my display.  However, the
color I need is a very light gray.  It is the same color I see on the pushed
down button in the task bar, as well as the back color on my scroll bars.  I
think I tried all of the vb constants, but none of them are this color.  Any
more ideas?
-GMG


>The color is vb3DHighlight, AFAIK.  Works with my color scheme, anyway.
>And Windows Standard (just checked).

>Jim Deutch
>MS Dev MVP



>> Hi.  I am trying to paint a background for a user-drawn button.  However,
>> this button must operate like an up-down button.  So the backcolor when
>the
>> button is down must be a lighter shade of gray.  For example, look at
>your
>> taskbar.  The currently activated app's button should be the color I am
>> talking about.  Or if you look at ms word, the selected alignment button
>> should also do it.  My problem is I don't know how to get that color.  I
>> don't believe it's one of the constants (all of my 3d-highlight type
>colors
>> are white, but my display shows this color as light gray.)  I need either
>a
>> way to find out this color, or maybe a way to BitBlt a mask onto a solid
>box
>> that I have already painted with vbButtonFace.  Any ideas?
>> -GMG

 
 
 

BitBlt question - modifying a background color

Post by Carl Ginno » Sat, 28 Feb 1998 04:00:00




Quote:> Hi.  I am trying to paint a background for a user-drawn button.  However,
> this button must operate like an up-down button.  So the backcolor when the
> button is down must be a lighter shade of gray.  For example, look at your
> taskbar.  The currently activated app's button should be the color I am
> talking about.  Or if you look at ms word, the selected alignment button
> should also do it.  My problem is I don't know how to get that color.  I
> don't believe it's one of the constants (all of my 3d-highlight type colors
> are white, but my display shows this color as light gray.)  I need either a
> way to find out this color, or maybe a way to BitBlt a mask onto a solid box
> that I have already painted with vbButtonFace.  Any ideas?
> -GMG

Gofreddo,

Depending on your color depth (16, 256, 16 bit, 24 bit color), the very light
gray may be a dithered pattern.  This gray looks lighter than a solid light
gray but is composed of a "checker board" pattern of gray and white.  If you
try using a solid color you may only get solid white or solid gray.  IF this is
your case, try using a dithered pattern to get what you want.

Carl.

 
 
 

BitBlt question - modifying a background color

Post by Gofredd » Sat, 28 Feb 1998 04:00:00


Thanks Carl.  OK, that was one idea I had.  When I look at MS Word, it does
sort of appear dithered, because I think I can see an alternating pixel
pattern.  However, I would like to avoid this if possible.  Now keep in
mind, my display colors are completely normal:  my buttonface is
medium-light gray (&H00C0C0C0&);  my buttonshadow is medium-dark gray
(&H00808080&); and the color I am seeing, for example on the pushed down
button on the taskbar, is light-gray (&H00E0E0E0&).  When I use that color
(as a numeric constant), my control looks perfect.  But of course I don't
want to hardcode that color.  There must be a constant I can use to get that
color.  I suppose the other way I could do it is to dither the button face
color with the button highlight color.  Or maybe I could just sort of
average those two.  Does anyone have any code to do either of those two
things?  Will actually averaging the two colors work?  Thanks.
-GMG




>> Hi.  I am trying to paint a background for a user-drawn button.  However,
>> this button must operate like an up-down button.  So the backcolor when
the
>> button is down must be a lighter shade of gray.  For example, look at
your
>> taskbar.  The currently activated app's button should be the color I am
>> talking about.  Or if you look at ms word, the selected alignment button
>> should also do it.  My problem is I don't know how to get that color.  I
>> don't believe it's one of the constants (all of my 3d-highlight type
colors
>> are white, but my display shows this color as light gray.)  I need either
a
>> way to find out this color, or maybe a way to BitBlt a mask onto a solid
box
>> that I have already painted with vbButtonFace.  Any ideas?
>> -GMG

>Gofreddo,

>Depending on your color depth (16, 256, 16 bit, 24 bit color), the very
light
>gray may be a dithered pattern.  This gray looks lighter than a solid light
>gray but is composed of a "checker board" pattern of gray and white.  If
you
>try using a solid color you may only get solid white or solid gray.  IF
this is
>your case, try using a dithered pattern to get what you want.

>Carl.

 
 
 

BitBlt question - modifying a background color

Post by Gofredd » Sat, 28 Feb 1998 04:00:00


OK - I dont think averaging the two colors as longs will work (I got a shade
of blue as the result).  Anyone know how to average colors?
-GMG


>Thanks Carl.  OK, that was one idea I had.  When I look at MS Word, it does
>sort of appear dithered, because I think I can see an alternating pixel
>pattern.  However, I would like to avoid this if possible.  Now keep in
>mind, my display colors are completely normal:  my buttonface is
>medium-light gray (&H00C0C0C0&);  my buttonshadow is medium-dark gray
>(&H00808080&); and the color I am seeing, for example on the pushed down
>button on the taskbar, is light-gray (&H00E0E0E0&).  When I use that color
>(as a numeric constant), my control looks perfect.  But of course I don't
>want to hardcode that color.  There must be a constant I can use to get
that
>color.  I suppose the other way I could do it is to dither the button face
>color with the button highlight color.  Or maybe I could just sort of
>average those two.  Does anyone have any code to do either of those two
>things?  Will actually averaging the two colors work?  Thanks.
>-GMG




>>> Hi.  I am trying to paint a background for a user-drawn button.
However,
>>> this button must operate like an up-down button.  So the backcolor when
>the
>>> button is down must be a lighter shade of gray.  For example, look at
>your
>>> taskbar.  The currently activated app's button should be the color I am
>>> talking about.  Or if you look at ms word, the selected alignment button
>>> should also do it.  My problem is I don't know how to get that color.  I
>>> don't believe it's one of the constants (all of my 3d-highlight type
>colors
>>> are white, but my display shows this color as light gray.)  I need
either
>a
>>> way to find out this color, or maybe a way to BitBlt a mask onto a solid
>box
>>> that I have already painted with vbButtonFace.  Any ideas?
>>> -GMG

>>Gofreddo,

>>Depending on your color depth (16, 256, 16 bit, 24 bit color), the very
>light
>>gray may be a dithered pattern.  This gray looks lighter than a solid
light
>>gray but is composed of a "checker board" pattern of gray and white.  If
>you
>>try using a solid color you may only get solid white or solid gray.  IF
>this is
>>your case, try using a dithered pattern to get what you want.

>>Carl.

 
 
 

BitBlt question - modifying a background color

Post by Carl Ginno » Sat, 28 Feb 1998 04:00:00




Quote:> OK - I dont think averaging the two colors as longs will work (I got a shade
> of blue as the result).  Anyone know how to average colors?
> -GMG

You could average the Red, Green and Blue components separately, then recombine
them with the RGB() function.

iRed1 = Color1 \ &H10000&
iRed2 = Color2 \ &H10000&
iGreen1 = (Color1 AND &HFF00&) \ &H100&
iGreen2 = (Color2 AND &HFF00&) \ &H100&
iBlue1 = Color1 AND &HFF&
iBlue2 = Color2 AND &HFF&

ColorAve = RGB((iRed1+iRed2)\2,(iGreen1+iGreen2)\2, (iBlue1+iBlue2)\2)

I sometimes use the API call GetSysColor() to get system colors.  The API
constants that start with COLOR_ don't include a light button face, only button
face, highlight, shadow and text.

Carl.

 
 
 

BitBlt question - modifying a background color

Post by Gofredd » Sat, 28 Feb 1998 04:00:00


Thanks again Carl.  I got it!  It works perfectly (or at least it looks good
on my display.)  I had already written this by the time you posted yours,
but it is simmilar.  I may decide to use yours instead because I'm sure it's
quicker.  I will have to use GetSysColor to get the actual values, so I may
need some help with that (hopefully I can get it myself).

Thanks to all you guys for your help.  I think this really solves the
problem.  I wonder if you guys could try it out on your machine and see if
it looks right.  The two colors to average are whatever shade of grey
vbButtonFace produces (you have to use the actual color, not the
vbButtonFace constant) and either (I am not sure which one yet)
vb3DHighlight or just vbWhite.  Those two are the same on my display, so I
wonder if anyone else can see a difference when you do the average.  Thanks
for your help!

Here's my color averaging function:

Private Function AverageColors(ByVal iColor1 As Long, iColor2 As Long) As
Long
    Dim xRed As Long
    Dim xGreen As Long
    Dim xBlue As Long
    xRed = (GetRedAmount(iColor1) + GetRedAmount(iColor2)) \ 2
    xGreen = (GetGreenAmount(iColor1) + GetGreenAmount(iColor2)) \ 2
    xBlue = (GetBlueAmount(iColor1) + GetBlueAmount(iColor2)) \ 2
    AverageColors = RGB(xRed, xGreen, xBlue)
End Function

Private Function GetRedAmount(ByVal iColor As Long) As Long
    GetRedAmount = iColor Mod 256
End Function

Private Function GetGreenAmount(ByVal iColor As Long) As Long
    GetGreenAmount = (iColor \ 256) Mod 256
End Function

Private Function GetBlueAmount(ByVal iColor As Long) As Long
    GetBlueAmount = (iColor \ 256 ^ 2) Mod 256
End Function




>> OK - I dont think averaging the two colors as longs will work (I got a
shade
>> of blue as the result).  Anyone know how to average colors?
>> -GMG

>You could average the Red, Green and Blue components separately, then
recombine
>them with the RGB() function.

>iRed1 = Color1 \ &H10000&
>iRed2 = Color2 \ &H10000&
>iGreen1 = (Color1 AND &HFF00&) \ &H100&
>iGreen2 = (Color2 AND &HFF00&) \ &H100&
>iBlue1 = Color1 AND &HFF&
>iBlue2 = Color2 AND &HFF&

>ColorAve = RGB((iRed1+iRed2)\2,(iGreen1+iGreen2)\2, (iBlue1+iBlue2)\2)

>I sometimes use the API call GetSysColor() to get system colors.  The API
>constants that start with COLOR_ don't include a light button face, only
button
>face, highlight, shadow and text.

>Carl.

 
 
 

BitBlt question - modifying a background color

Post by Jim » Sat, 28 Feb 1998 04:00:00


You've had a lot of responses here, so I'll throw my 2 cents in and see
what happens.

When drawing the system colors on the screen, I tend to let Windows handle
the color management.  I get the color I need based on two things.  The VB
constant and the GetSysColor API function.  

Declare Function GetSysColor Lib "user32" Alias "GetSysColor" (ByVal nIndex
As Long) As Long

Now, the nIndex parameter expects a number from 1 to about umm... about 24
or so... (correct me there if I'm wrong :-)  The VB constants are
equivalent, but they have the high bit turned on.  So, to get the correct
rgb values I just call:

uColor = GetSysColor(vbButtonFace And &h7FFFFFFF)

The second issue you seemed to have was with the coloring of your display
driver.  I do not know why your highlight colors would show up as white.
I'd have to see your system I guess.  :-)   I'm running a p-166 with NT4
sp3 and 16-bit color on a ATI Rage 3D card.  No problems with the grays for
me.

--
Jim Houghtaling
Technical Development Advisor
HBO & Company, Longwood, FL

One-seventh of your life will be spent on Mondays.

 
 
 

BitBlt question - modifying a background color

Post by Gofredd » Sat, 28 Feb 1998 04:00:00


Hi Jim.
I am running in 16-bit color.  The thing is, I really think the color I am
looking for is different than that vb3DHighlight color.  I have looked at 3
different systems with totally different display settings, and they all had
a different color for the 3DHighlight than the one I want.  Now is your
3DHighlight light grey?  Because every one I have looked at here is white.
But I need light grey =)  I totally agree with you that if a windows color
constant exists and is available I would prefer to use it.  But I haven't
found that yet, and I am pretty sure it is not 3dhighlight.  The closest I
have come so far is to average the buttonface and the 3dhighlight colors.
But I still think that's a little bit off.  Any ideas?
-GMG


>You've had a lot of responses here, so I'll throw my 2 cents in and see
>what happens.

>When drawing the system colors on the screen, I tend to let Windows handle
>the color management.  I get the color I need based on two things.  The VB
>constant and the GetSysColor API function.

>Declare Function GetSysColor Lib "user32" Alias "GetSysColor" (ByVal nIndex
>As Long) As Long

>Now, the nIndex parameter expects a number from 1 to about umm... about 24
>or so... (correct me there if I'm wrong :-)  The VB constants are
>equivalent, but they have the high bit turned on.  So, to get the correct
>rgb values I just call:

>uColor = GetSysColor(vbButtonFace And &h7FFFFFFF)

>The second issue you seemed to have was with the coloring of your display
>driver.  I do not know why your highlight colors would show up as white.
>I'd have to see your system I guess.  :-)   I'm running a p-166 with NT4
>sp3 and 16-bit color on a ATI Rage 3D card.  No problems with the grays for
>me.

>--
>Jim Houghtaling
>Technical Development Advisor
>HBO & Company, Longwood, FL

>One-seventh of your life will be spent on Mondays.

 
 
 

BitBlt question - modifying a background color

Post by Jim Deutc » Tue, 03 Mar 1998 04:00:00


Ha!  You're right!  It's a dither of vbButtonFace and vb3DHighlight!  I
never zoomed in enough to notice....

Averaging the RGB components of the two doesn't give the right dither for
me: in fact, it's a bit surprising that it dithers at all in 16-bit color
(the two colors differ only by g = 191/192).  The overall color is a poor
match to the dither.

You can dither colors in High- or True-color video by using PSet (or
SetPixel(), which will be considerably faster if you cache the hDC), or by
using CreatePatternBrush() or one of its relatives (I'll need to experiment
some, as I've never done this...)

Jim Deutch
MS Dev MVP



Quote:> Hi Jim.
> I am running in 16-bit color.  The thing is, I really think the color I
am
> looking for is different than that vb3DHighlight color.  I have looked at
3
> different systems with totally different display settings, and they all
had
> a different color for the 3DHighlight than the one I want.  Now is your
> 3DHighlight light grey?  Because every one I have looked at here is
white.
> But I need light grey =)  I totally agree with you that if a windows
color
> constant exists and is available I would prefer to use it.  But I haven't
> found that yet, and I am pretty sure it is not 3dhighlight.  The closest
I
> have come so far is to average the buttonface and the 3dhighlight colors.
> But I still think that's a little bit off.  Any ideas?
> -GMG

 
 
 

BitBlt question - modifying a background color

Post by Gotstei » Wed, 04 Mar 1998 04:00:00


&H8000000F is the button face color, there are other &H800000??
combinations. Try them out. I dont have them with me now, look them up in
the help menus or documentation.

 
 
 

BitBlt question - modifying a background color

Post by Gofredd » Wed, 04 Mar 1998 04:00:00


Hi Jim.  Thanks for looking into that.  OK.  Now you are getting to my boundaries of expertise.  I have used CreatePatternBrush
before, but I am not ready to write my own routine from scratch.  If you happen to come across or work on this dither routine, I
would love to see how it's done.  I still have to finish reading Appleman before I will be ready to do that myself.  Thanks again.
-GMG
~~~~~~~~~~~~~~~~~~~~~~~~~
Visit Gofreddo's VB Page:
www.cs.utexas.edu/users/gglaze/vb
~~~~~~~~~~~~~~~~~~~~~~~~~


>Ha!  You're right!  It's a dither of vbButtonFace and vb3DHighlight!  I
>never zoomed in enough to notice....

>Averaging the RGB components of the two doesn't give the right dither for
>me: in fact, it's a bit surprising that it dithers at all in 16-bit color
>(the two colors differ only by g = 191/192).  The overall color is a poor
>match to the dither.

>You can dither colors in High- or True-color video by using PSet (or
>SetPixel(), which will be considerably faster if you cache the hDC), or by
>using CreatePatternBrush() or one of its relatives (I'll need to experiment
>some, as I've never done this...)

>Jim Deutch
>MS Dev MVP



>> Hi Jim.
>> I am running in 16-bit color.  The thing is, I really think the color I
>am
>> looking for is different than that vb3DHighlight color.  I have looked at
>3
>> different systems with totally different display settings, and they all
>had
>> a different color for the 3DHighlight than the one I want.  Now is your
>> 3DHighlight light grey?  Because every one I have looked at here is
>white.
>> But I need light grey =)  I totally agree with you that if a windows
>color
>> constant exists and is available I would prefer to use it.  But I haven't
>> found that yet, and I am pretty sure it is not 3dhighlight.  The closest
>I
>> have come so far is to average the buttonface and the 3dhighlight colors.
>> But I still think that's a little bit off.  Any ideas?
>> -GMG

  Gofreddo.vcf
< 1K Download
 
 
 

1. How?! Rendering FROM background buffer -- OR -- modifying PIXELFORMATDESCRIPTOR

Hi!
        (I think) I want to render a scene but instead of using color data
from the GL functions, I want to get them from the background buffer (or a
bitmap array).  For example, I have the same scene rendered in GL_BACK and
GL_FRONT, then render a line normally to GL_FRONT, then render again *from*
GL_BACK, erasing the previously rendered line.  If that's possible, that's got
to be the fastest way to do rubber-banding (with hopefully unnoticable
flicker).  Is this possible?

If not... well obviously I don't quite understand what's involved but I don't
imagine it would be TOO hard to modify the PIXELFORMATDESCRIPTOR to make this
possible. ???  But is modifying that plausible?  Maybe it could be done in an
extension?  Of course, I have no idea what's involved in that, either.  I'm
really out of my element here.

But thanks for any help!!
Mike

2. FLC to AVI?

3. Bitblt monochrome bimap in forecolor plus transparent background

4. Custom graphic on WIN controls

5. Newbie question about replacing colors and creating transparent background

6. Please help with EDGES!

7. Background color and MFC/OpenGL question

8. The Art of lossless image compression, 11th release

9. background colored 1DTexture looks darker than background

10. IBM MMR-Modified Modified READ

11. Modifying Canvas does not modify the underlying bitmap!!!

12. Color-palette modifying program wanted