Color

Hi,

I'm a new programmer with C++

We are using VC++6 I'd like to know if it's possible to give a backgroung 
color to a label (static text) from my code.

I want to change the background color of a lable (static text) depending on 
what the user choose from a combo box color

Thanks
0
Hermione (11)
4/23/2006 2:00:01 AM
vc.mfc 33608 articles. 0 followers. Follow

9 Replies
926 Views

Similar Articles

[PageSpeed] 22

I think you can subclass your "static class" window and write your own 
WM_ERASEBKGND message handler....

Something like this:

------%<-----------%<---------------
class CMyStaticText: public CStatic
{
public:
  afx_msg BOOL OnEraseBkgnd(CDC *);

  DECLARE_MESSAGE_MAP()
}

BEGIN_MESSAGE_MAP(CMyStaticText, CStatic)
  ON_ERASEBKGND()
END_MESSAGE_MAP()

BOOL CMyStaticText::OnEraseBkgnd(CDC *pDC)
{
  // Use pDC do fill the background here!
}

"Hermione" <Hermione@discussions.microsoft.com> wrote in message 
news:2B278F8A-B600-430E-9C20-0BD51DE64F70@microsoft.com...
> Hi,
>
> I'm a new programmer with C++
>
> We are using VC++6 I'd like to know if it's possible to give a backgroung
> color to a label (static text) from my code.
>
> I want to change the background color of a lable (static text) depending 
> on
> what the user choose from a combo box color
>
> Thanks 


0
me3665 (29)
4/23/2006 2:43:29 AM
you will have to subclass the CStatic class, subclass it and override the 
OnPant(...)
handler and fill the background of the control using the FillRect(...).

Now associate the control on the dialog with the newly created class.

-- 
Vipin Aravind
http://www.explorewindows.com


"Hermione" <Hermione@discussions.microsoft.com> wrote in message 
news:2B278F8A-B600-430E-9C20-0BD51DE64F70@microsoft.com...
> Hi,
>
> I'm a new programmer with C++
>
> We are using VC++6 I'd like to know if it's possible to give a backgroung
> color to a label (static text) from my code.
>
> I want to change the background color of a lable (static text) depending 
> on
> what the user choose from a combo box color
>
> Thanks 


0
vipin (697)
4/23/2006 2:50:16 AM
You can also try mapping OnCtrlColor of the parent window.

eg:

HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
     HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    if( pWnd == GetDlgItem(ID_MY_STATIC )
    {
        hbr = // Create brush for your static control
        return hbr;
    }


     return hbr;
}

"Hermione" <Hermione@discussions.microsoft.com> wrote in message
news:2B278F8A-B600-430E-9C20-0BD51DE64F70@microsoft.com...
> Hi,
>
> I'm a new programmer with C++
>
> We are using VC++6 I'd like to know if it's possible to give a backgroung
> color to a label (static text) from my code.
>
> I want to change the background color of a lable (static text) depending
on
> what the user choose from a combo box color
>
> Thanks


0
jibesh_vp (12)
4/23/2006 3:59:49 AM
Better still, avoid this solution entirely!  If you need to, you can write a reflected
WM_CTLCOLOR handler, which you'll find listed in the wizard as "=WM_CTLCOLOR", and do the
work where it belongs, in the static control.  It rarely if ever makes sense to put this
sort of handler in the parent of a control.  This is a throwback to the rather poor design
Microsoft did for controls, and the reflected handlers avoid having to deal with this
defective design (why in the world would the parent know or care what color the child
control is supposed to be?  This violates most good design priniciples!)
					joe

On Sun, 23 Apr 2006 09:29:49 +0530, "jibesh" <jibesh_vp@hotmail.com> wrote:

>You can also try mapping OnCtrlColor of the parent window.
>
>eg:
>
>HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
>{
>     HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
>
>    if( pWnd == GetDlgItem(ID_MY_STATIC )
>    {
>        hbr = // Create brush for your static control
>        return hbr;
>    }
>
>
>     return hbr;
>}
>
>"Hermione" <Hermione@discussions.microsoft.com> wrote in message
>news:2B278F8A-B600-430E-9C20-0BD51DE64F70@microsoft.com...
>> Hi,
>>
>> I'm a new programmer with C++
>>
>> We are using VC++6 I'd like to know if it's possible to give a backgroung
>> color to a label (static text) from my code.
>>
>> I want to change the background color of a lable (static text) depending
>on
>> what the user choose from a combo box color
>>
>> Thanks
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15974)
4/23/2006 4:43:32 AM
Note that if the purpose is to change the background (or text) color, this solution
requires not only painting the background, but painting the text also.

Better to use the =WM_CTLCOLOR (not the WM_CTLCOLOR) handler, the reflected WM_CTLCOLOR
handler, which allows you to set the background color and text color.  You will probably
also want to SetBkMode(TRANSPARENT)
					joe

On Sun, 23 Apr 2006 08:20:16 +0530, "Vipin [MVP]" <Vipin@nospam.com> wrote:

>you will have to subclass the CStatic class, subclass it and override the 
>OnPant(...)
>handler and fill the background of the control using the FillRect(...).
>
>Now associate the control on the dialog with the newly created class.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15974)
4/23/2006 4:45:24 AM
yes, WM_CTLCOLOR reflect handler is the most appropriate.

-- 
Vipin Aravind
http://www.explorewindows.com


"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:1g1m4218v3vjjk7pt381e4n3kn73ucrhaf@4ax.com...
> Note that if the purpose is to change the background (or text) color, this 
> solution
> requires not only painting the background, but painting the text also.
>
> Better to use the =WM_CTLCOLOR (not the WM_CTLCOLOR) handler, the 
> reflected WM_CTLCOLOR
> handler, which allows you to set the background color and text color.  You 
> will probably
> also want to SetBkMode(TRANSPARENT)
> joe
>
> On Sun, 23 Apr 2006 08:20:16 +0530, "Vipin [MVP]" <Vipin@nospam.com> 
> wrote:
>
>>you will have to subclass the CStatic class, subclass it and override the
>>OnPant(...)
>>handler and fill the background of the control using the FillRect(...).
>>
>>Now associate the control on the dialog with the newly created class.
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
> -- 
> NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth 


0
vipin (697)
4/23/2006 5:14:54 AM
Joseph,

> Better still, avoid this solution entirely!  If you need to, you can write 
> a reflected
> WM_CTLCOLOR handler, which you'll find listed in the wizard as 
> "=WM_CTLCOLOR", and do the
> work where it belongs, in the static control.  It rarely if ever makes 
> sense to put this
> sort of handler in the parent of a control.  This is a throwback to the 
> rather poor design
> Microsoft did for controls, and the reflected handlers avoid having to 
> deal with this
> defective design (why in the world would the parent know or care what 
> color the child
> control is supposed to be?  This violates most good design priniciples!)

Uh, doesn't that make sense given that Windows was not object-oriented at 
the time, and that, in general, programmers would write window procedures 
for the parent windows and not for controls (which already had window 
procedures)? Before MFC, adding a notification handler was quite a bit more 
work than subclassing a control.

I understand how it should really be now, but at the time, it seems to me 
that the design made sense given the situation.

-- 
Jonathan Wood
SoftCircuits
http://www.softcircuits.com


0
jwood (1291)
4/23/2006 7:41:58 PM
You have got lot of good responses, but here is some sample code:

http://www.codeproject.com/staticctrl/XColorStatic.asp
http://www.codeproject.com/staticctrl/coloredit_colorstatic.asp

--
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"Hermione" <Hermione@discussions.microsoft.com> wrote in message
news:2B278F8A-B600-430E-9C20-0BD51DE64F70@microsoft.com...
> Hi,
>
> I'm a new programmer with C++
>
> We are using VC++6 I'd like to know if it's possible to give a backgroung
> color to a label (static text) from my code.
>
> I want to change the background color of a lable (static text) depending
on
> what the user choose from a combo box color
>
> Thanks


0
ajaykalra (6842)
4/24/2006 4:11:40 AM
Well, given the design, it made sense, but that's a commentary on the fact that the design
was done in such a way as to REQUIRE that the parent know how the child was implemented!
When I started programming Windows, I kept wondering "Haven't these people EVER heard of
modularization and separation of concerns?  How could they have done anything this dumb?"
When I started using MFC, it became obvious that the right way to do things was by
subclassing (which could have been done in the old Windows as well, but that wasn't being
touted as a solution because, apparently, it was "too complicated")
						joe

On Sun, 23 Apr 2006 13:41:58 -0600, "Jonathan Wood" <jwood@softcircuits.com> wrote:

>Joseph,
>
>> Better still, avoid this solution entirely!  If you need to, you can write 
>> a reflected
>> WM_CTLCOLOR handler, which you'll find listed in the wizard as 
>> "=WM_CTLCOLOR", and do the
>> work where it belongs, in the static control.  It rarely if ever makes 
>> sense to put this
>> sort of handler in the parent of a control.  This is a throwback to the 
>> rather poor design
>> Microsoft did for controls, and the reflected handlers avoid having to 
>> deal with this
>> defective design (why in the world would the parent know or care what 
>> color the child
>> control is supposed to be?  This violates most good design priniciples!)
>
>Uh, doesn't that make sense given that Windows was not object-oriented at 
>the time, and that, in general, programmers would write window procedures 
>for the parent windows and not for controls (which already had window 
>procedures)? Before MFC, adding a notification handler was quite a bit more 
>work than subclassing a control.
>
>I understand how it should really be now, but at the time, it seems to me 
>that the design made sense given the situation.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15974)
5/1/2006 4:48:26 PM
Reply:

Similar Artilces:

CDialog background color
Hello, How can change the background colour of a dialog programmatically? Best regards >How can change the background colour of a dialog programmatically? Handle the WM_CTLCOLORDLG message (OnCtlColor CTLCOLOR_DLG in MFC) and return a brush of the colour you want. Dave -- MVP VC++ FAQ: http://www.mvps.org/vcfaq Thanks but it didn't work! here is the code that I wrote: HBRUSH CDialogAppCon::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here // TODO: Return a different b...

Change cell color after processes
In this program which works until I added the .cells color - basically I want to color the cell if it existed and was moved or a different color if the file was not found. I keep getting a type mismatch. The code is below. 'Primary program ' Sub RunThroughList() Dim I As Long Dim Destination As String Dim Lastrow As Long Lastrow = Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row For I = 1 To Lastrow MoveFiles Range("A" & I).Value, "P:\Web_ICC\Archive_Test\", I Cells("A", I).Interior.ColorIndex = 6 Next End Sub 'Sub routin...

Help formatting text color based on formula
I have searched the forum and find some things that help but not quite enough. I have a table of numbers. In fact there are 300 rows of 5 colums of numbers. What I would like to do is to change the color of the number if it matches one of 5 other numbers. Example Reference #s 2 6 23 43 48 01 02 09 08 14 06 14 23 43 44 03 11 23 24 52 etc etc etc etc The example list is already populated. When the reference numbers are entered I want any number in the example list that matches any number in the reference list to change to a specified color. Any way to...

Change border color of active cell??
How can i change the border color of the active cell in Ecell 2004 for MAC?? thanks ...

Color Scheme Disapeared?
Several lines were shaded the standard beige that appears on the color scheme chart when the color chart icon is pressed in Excel 2000. To my surprise ... and for no known reason... all lines shaded with that color changed to a cruddy gray. When I looked at the chart again, where the beige had been is now that crummy gray... as it appears in several other boxes of that chart now. When I place my cursor over those boxes of gray, I get a text reading of "Color Scheme" rather than the name of the color the cursor is on. What the heck happened and how do I get that beige back? Never ...

Color
Hi, I'm a new programmer with C++ We are using VC++6 I'd like to know if it's possible to give a backgroung color to a label (static text) from my code. I want to change the background color of a lable (static text) depending on what the user choose from a combo box color Thanks I think you can subclass your "static class" window and write your own WM_ERASEBKGND message handler.... Something like this: ------%<-----------%<--------------- class CMyStaticText: public CStatic { public: afx_msg BOOL OnEraseBkgnd(CDC *); DECLARE_MESSAGE_MAP() } BEGIN_MES...

re: Changing subject/conversation text color <20061123223842noreply@takethisout.registrme.sent.com>
Never mind. I changed it with "Other Settings, Shade Group Headings". Couldn't change the color, but the color is now black on gray (my system setting) and is a lot better. EggHeadCafe.com - .NET Developer Portal of Choice http://www.eggheadcafe.com ...

Excel 2007 Change Standard Colors How?
Greetings, I just started Excel 2007. My spreadsheets typically have a lot of cells that are color filled. When I work on a old or new one, I find the light bright color fills of 2003 aren't there as defaults or easy to find without multiple clicks. Is there a way to change the standard colors presented when you click on the paint bucket? Thanks for your help! ...

color in checkbox?
Any way you can have a checkbox turn a color (fill in black or whatever color) when you click on it instead of a checkmark? -- Thanks, Sharon SHARON wrote: > Any way you can have a checkbox turn a color (fill in black or > whatever color) when you click on it instead of a checkmark? Not with a genuine form-field checkbox (although with an exit macro you could change the checkbox's font color, that's not "instead of a checkmark"). Using the technique at http://gregmaxey.mvps.org/Add_Toggle_Objects.htm, though, you can make the "checkbox" b...

color code
I have trying to do this, but to no avail. I want cells to change color like: more than 60 days before certain date - they're green 1 - 60 days - they're yellow 0 days and days after - they're red Format | Conditional Format | Cell Value is < A1-60 where the date to check against is in cell A1. Define your Format. Same for the other formats -- HTH... Jim Thomlinson "Shihachi" wrote: > I have trying to do this, but to no avail. > I want cells to change color like: > more than 60 days before certain date - they're green > 1 - ...

color tab on spreadsheet
hi I have a file with 20 tab and names nearly same. So I would like to color the tab. Do you know how to do it thanks for hel Benjamin Is only possible in Excel 2002 and 2003 Ben -- Regards Ron de Bruin (Win XP Pro SP-1 XL2002 SP-2) www.rondebruin.nl "Ben.c" <anonymous@discussions.microsoft.com> wrote in message news:30C7D4B9-F271-45AF-A618-66680BF33EDE@microsoft.com... > hi, > I have a file with 20 tab and names nearly same. So I would like to color the tab. Do you know how to do it ? > thanks for help > Benjamin Only way is to get Office XP (excel 2002)...

printing in color paper
Hi, I'm trying to print in blue and red paper but the text always appear black no matter which font color I choose. Does any one have tried to print non black font in non white paper? Thanks a lot for your help Neither Word nor your printer has any way of knowing what color paper you are putting into your printer. If you try to print (for instance) with red ink on green paper, of course it will look black! On Feb 1, 11:41=A0am, MVR <M...@discussions.microsoft.com> wrote: > Hi, I'm trying to print in blue and red paper but the text always appear > black no m...

Result changes cell color
Is there a way to fill a cell with a color depending on the result? Basically, I want the following: If cell = 1 Fill cell with Red If cell = 2 Fill cell with Yellow If cell = 3 Fill cell with Green Thanks for any help. format>conditional format>easy from there -- Don Guillett SalesAid Software donaldb@281.com "GSBohn" <genie@cfl.rr.com> wrote in message news:uDoqd.47388$Oc.10064@tornado.tampabay.rr.com... > Is there a way to fill a cell with a color depending on the result? > > Basically, I want the following: > > If cell = 1 Fill cell with ...

changing font color in multiple textboxes
Hello, I am trying to find out how (if its possible) to change the font color of multiple textboxes at the same time. I changed my background and now i need all the textboxes to have white text instead of black. I have over 100 textboxes so going and changing each text box is quite annoying. Any help is appreciated. kahlan715 wrote: > I am trying to find out how (if its possible) to change the font color of > multiple textboxes at the same time. I changed my background and now i need > all the textboxes to have white text instead of black. I have over 100 > textboxe...

How do I change cell color in excel based on text input?
I want the cell format (meaning color of the cell) to change based upon the text entered. I have used up the conditioal formatting. It only allows three formats, and i require more. I am inquiring if this can be made into a formula for a cell to have the color change upon certain text phrases? Try this event code. Option Compare Text Private Sub Worksheet_Change(ByVal Target As Range) Set r = Range("A1:A20") If Intersect(Target, r) Is Nothing Then Exit Sub End If On Error GoTo Endit Application.EnableEvents = False vals = Array("Cat", "Dog", "Gopher&...

Colors in Outlook Today
Is there any way I can add additional styles to Outlook Today to give me more color schemes besides Summer and Winter? -Mike Not natively from Outlook. -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. After furious head-scratching, Mike D. asked this group: | Is there any way I can add additional styles to Outlook Today to give | me more color schemes besides Summer and Winter? | | -Mike ...

Change color of Track Changes Highlighting
How do I change the color of the highlighting when track changes is enabled? A colleague reviewed my work and entered changes but the highlighting is a light green color and is almost invisible. In MS word there is an option button on the "Highlight Changes" dialog. Where is the similar control in Excel (2000)?? Thanks for your help. Bob Julian ...

How to Paste Link a cell with color and maintain the color
...

color formatting of partial text of a cell in excel in bulk
i want to make a cell with multicolor text......... how to do it in bulk(e.g as we do it in replace all) If the text displayed in the cell is the result of a formula in that cell, you cannot have more than one color. If your data is a pure text entry, you can have multi-colored text, but you will need to use a macro to do more than one cell at a time. If your cell entries are second condition (pure text), then give us more information about what you want to do. Rick "chetan" <nishuu.chetan@gmail.com> wrote in message news:8c6b5711-0808-4f53-8462-94b08d180d91@z16g2000...

Color & CListCtrl
Hi folks, Does someone know and to give to a particular cell of my CListCtrl a background color and a color text? Is it possible? Thanks for any help Regards, Salim Here's a link to an article on using OnCustomDraw(); http://www.codeguru.com/listview/LVHighlight.shtml Tom "Salim GOMRI" <salim.gomri@wanadoo.fr> wrote in message news:bg7sh9$s2v$1@news-reader5.wanadoo.fr... > Hi folks, > > Does someone know and to give to a particular cell of my CListCtrl a > background color and a color text? > > Is it possible? > > Thanks for any help > &...

Cell Fill Color
I'm using Excel '03 and filling cells w/ a color (with the paint bucket). The color does not show up in my spreadsheet, but does show up when I print. Every now and then I get a fill color to show up in the sheet, but if I click in another cell, the colored cell goes back to white. Hi Jack, See MSKB article # 320531: 'Changes to the fill color and the fill pattern are not displayed in Office programs' http://support.microsoft.com/default.aspx?scid=kb;en-us;320531 --- Regards, Norman "JackBScott" <JackBScott@discussions.microsoft.com> wrote in mes...

Chart Color Defaults
I'm not a big fan of Excel's default chart colors. I can change them as needed & experiment w/ what looks best, but are there any downloads that would allow me to conveniently reset the colors in one fell swoop? Thanks. -- Jay Jay wrote: > I'm not a big fan of Excel's default chart colors. I can change them as > needed & experiment w/ what looks best, but are there any downloads that > would allow me to conveniently reset the colors in one fell swoop? Thanks. > -- > Jay Why not just create a macro that you could run that sets the default colour...

Font Color Conditional Formatting/Color Scaling
tWithin a matrix of data, I want to use two conditional formating/color scaling: one for the background color of the cell, the second for the font color corresponding to a different (but same size) data matrix. I know how to use the conditional formatting/color scaling for the background color--however would it be possible to have a different color scaling for the font color (and applied to one data matrix but referencing a separate data matrix)? Or even, can I at least use the conditional formatting/color scaling but changing the font color instead of the background cell col...

line color
I have an XY chart using dates for the X. The Y axis is made up from a column of equations. When I create the chart, the lines that connect the data points don't show up. I have been into the plot format and tried making the lines come up in different colors, but nothing seems to work. However, when I make a column that is equal to just the value of the other cells and use this new column to graph the chart, the lines show up, but the dates change to numbers between 0 and 12 on the chart. How do I make the lines show up without changing the any of the data? Can you give an exa...

Microsoft Outlook Background Default Color....
How can we change the default background color from white to black and the font color from black to white on both messages sent, received and replied to? We have an employee who has trouble seeing and can read white text on a black background. However, when she replies to e- mails, anyone who gets the reply just sees a blank white screen. Thanks for your assistance! ...