Changing background colors 
Author Message
 Changing background colors

Is there an easy way to dynamically change the background color of a window?
I have a set of CStatic controls that I am using to display stock quotes.
When the price increases I wan the background color to be in green and when
the price decreases, change the background to red.

Is there any way to just change the window's background brush, invalidate
the rectangle, and have the window repainted with the new background color?

I've tried things such as trapping the WM_ERASEBKGND and WM_CTLCOLOR
messages and providing a brush with the new color.  But it seems that the
background is then overwritten in the windows paint procedure.

Any ideas?



Tue, 13 Sep 2005 19:36:57 GMT  
 Changing background colors
Handling OnCtlColor should work fine for a CStatic. Make sure you give it an
ID other than IDC_STATIC. There are several examples related to this at
www.codeguru.com

--
Ajay Kalra [MVP - VC++]


Quote:
> Is there an easy way to dynamically change the background color of a
window?
> I have a set of CStatic controls that I am using to display stock quotes.
> When the price increases I wan the background color to be in green and
when
> the price decreases, change the background to red.

> Is there any way to just change the window's background brush, invalidate
> the rectangle, and have the window repainted with the new background
color?

> I've tried things such as trapping the WM_ERASEBKGND and WM_CTLCOLOR
> messages and providing a brush with the new color.  But it seems that the
> background is then overwritten in the windows paint procedure.

> Any ideas?



Tue, 13 Sep 2005 20:55:03 GMT  
 Changing background colors
In addition to the suggestions made, don't forget that the text background is also
specified. You can either do a SetBkColor() call in your WM_CTLCOLOR... handler, or do a
SetBkMode(TRANSPARENT) which then does not overwrite the text background with the
SetBkColor, but leaves the background showing through.
                                        joe

Quote:

>Is there an easy way to dynamically change the background color of a window?
>I have a set of CStatic controls that I am using to display stock quotes.
>When the price increases I wan the background color to be in green and when
>the price decreases, change the background to red.

>Is there any way to just change the window's background brush, invalidate
>the rectangle, and have the window repainted with the new background color?

>I've tried things such as trapping the WM_ERASEBKGND and WM_CTLCOLOR
>messages and providing a brush with the new color.  But it seems that the
>background is then overwritten in the windows paint procedure.

>Any ideas?

Joseph M. Newcomer [MVP]

Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Fri, 23 Sep 2005 21:24:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. changing background color of the text

2. How to change background color

3. Can't change background color of edit control

4. Changing background color in a composite control

5. changing background colors

6. Changing background color of dialog

7. Changing background color of a group box

8. Changing background colors in console.

9. Changing background color of label

10. Changing Background Color of Dialog View?

11. Help change background color of client area

12. Change background color

 

 
Powered by phpBB® Forum Software