Changing color of static text on a Dialog 
Author Message
 Changing color of static text on a Dialog

After all these years as a VC++ developer I am embarrassed to admit I forgot
how to change the color of a static text control on a Dialog.

This code does not work when added to OnInitDialog():

#define RGB_RED             RGB(255, 0, 0)
    CStatic* pWndStaticColor = (CStatic*)GetDlgItem(IDC_COLOR_TEST_STATIC);
    CDC * pDC = pWndStaticColor->GetDC();
    COLORREF oldTextColor = pDC->SetTextColor(RGB_RED);

Changing the first line as follows didn't fix it.
    CWnd* pWndStaticColor = GetDlgItem(IDC_COLOR_TEST_STATIC);

I also tried putting this code snippet before and after
CDialog::OnInitDialog(). This didn't help either.

What am I missing here?

Michael T.



Thu, 11 Sep 2003 04:02:48 GMT  
 Changing color of static text on a Dialog
Hi, Michael!

Forget what you're diong and handle the WM_CTLCOLORSTATIC message instead.

Jeff...
--
Please post all  follow-ups to the newsgroup only.


Quote:
> After all these years as a VC++ developer I am embarrassed to admit I forgot
> how to change the color of a static text control on a Dialog.

> This code does not work when added to OnInitDialog():

> #define RGB_RED             RGB(255, 0, 0)
>     CStatic* pWndStaticColor = (CStatic*)GetDlgItem(IDC_COLOR_TEST_STATIC);
>     CDC * pDC = pWndStaticColor->GetDC();
>     COLORREF oldTextColor = pDC->SetTextColor(RGB_RED);

> Changing the first line as follows didn't fix it.
>     CWnd* pWndStaticColor = GetDlgItem(IDC_COLOR_TEST_STATIC);

> I also tried putting this code snippet before and after
> CDialog::OnInitDialog(). This didn't help either.

> What am I missing here?

> Michael T.



Thu, 11 Sep 2003 04:09:27 GMT  
 Changing color of static text on a Dialog

Quote:

>After all these years as a VC++ developer I am embarrassed to admit I forgot
>how to change the color of a static text control on a Dialog.

For example code on doing this, see here:

www.mooremvp.freeserve.co.uk/Win32/w32tip37.htm

--
Bob Moore [WinSDK MVP]
http://www.mooremvp.freeserve.co.uk/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Do not reply via email unless specifically requested to do so.
Unsolicited email is NOT welcome and will go unanswered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Thu, 11 Sep 2003 05:10:02 GMT  
 Changing color of static text on a Dialog
OK Bob, I subclassed my static control with SubclassDlgItem and added the
message handler OnCtlColor. Then I pasted in the code from
www.mooremvp.freeserve.co.uk/Win32/w32tip37.htm as you suggested. But it
still doesn't work.

The problem is that I cannot determine what needs to be added so the
ON_WM_CTLCOLOR message gets sent to my OnCtlColor message handler for my
subclassed static control.

Any ideas?

Michael T.



|
| >After all these years as a VC++ developer I am embarrassed to admit I
forgot
| >how to change the color of a static text control on a Dialog.
|
| For example code on doing this, see here:
|
| www.mooremvp.freeserve.co.uk/Win32/w32tip37.htm
|
| --
| Bob Moore [WinSDK MVP]
| http://www.mooremvp.freeserve.co.uk/
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

| Do not reply via email unless specifically requested to do so.
| Unsolicited email is NOT welcome and will go unanswered.
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Thu, 11 Sep 2003 08:21:57 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Change the background color of a dialog box and change text color of Edit Box, Static Text, Rich Edit

2. change color of static text not working

3. How to change color of static text...

4. CHANGING COLOR OF STATIC TEXT

5. How to change color of text static control

6. Changing Color of Static Text and other controls?

7. changing the font color of a static text control

8. Changing the background color of a static text control

9. Changing color of static text

10. Change colors in static text control

11. Changing the color of the text in a static control

12. Changing font color in static text box

 

 
Powered by phpBB® Forum Software