Static text background color question 
Author Message
 Static text background color question

Hi,

   I need to color the background of a CStatic black (the text is white).
I'm overriding the
OnCtlColor method with the following :

  switch (nCtlColor) {
  case CTLCOLOR_STATIC:
    // Set the static text and background color
    pDC->SetTextColor(RGB(255, 255, 255));
    pDC->SetBkColor(RGB(0, 0, 0));
  default:
    return (HBRUSH)(m_pBkBrush->GetSafeHandle());
  }

The background color looks OK under the text that's printed (black bg white
text), but since the static control is sometimes wider than the text it
displays, the "left over" part remains white.  Also, sometimes the static
field has NO text in which case the whole thing is glaring white.

Any help is greatly appreciated.

Deanna



Sun, 22 Apr 2001 03:00:00 GMT  
 Static text background color question
Are you look for this ?
........::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

   switch (nCtlColor) {
       case CTLCOLOR_STATIC:
          pDC->SetTextColor(RGB(255, 255, 255));
          pDC->SetBkColor(RGB(0, 0, 0));
          hbr = ::CreateSolidBrush(RGB(0,0,0));
          pDC->SetBkMode(TRANSPARENT);
   }
   return hbr;

Quote:
}

> Hi,

>    I need to color the background of a CStatic black (the text is white).
> I'm overriding the
> OnCtlColor method with the following :

>   switch (nCtlColor) {
>   case CTLCOLOR_STATIC:
>     // Set the static text and background color
>     pDC->SetTextColor(RGB(255, 255, 255));
>     pDC->SetBkColor(RGB(0, 0, 0));
>   default:
>     return (HBRUSH)(m_pBkBrush->GetSafeHandle());
>   }

> The background color looks OK under the text that's printed (black bg white
> text), but since the static control is sometimes wider than the text it
> displays, the "left over" part remains white.  Also, sometimes the static
> field has NO text in which case the whole thing is glaring white.

> Any help is greatly appreciated.

> Deanna



Mon, 23 Apr 2001 03:00:00 GMT  
 Static text background color question
This code is dangerous. For example, it does a ::CreateSolidBrush on
EVERY OnCtlColor call, but NEVER deletes it! This will leak brushes
all over the place, and eventually you will consume even NT's massive
GDI space! Instead, create the brush once when the class is
constructed and delete it in the destructor (this gives you one brush
per class instance, which also allows you to have separate colors for
different instances). Just create your own subclass of CStatic and add
a CBrush member variable.
                                joe

On Thu, 05 Nov 1998 21:06:52 +0800, Mak Wing Sze

Quote:

>Are you look for this ?
>........::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
>{
>   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

>   switch (nCtlColor) {
>       case CTLCOLOR_STATIC:
>          pDC->SetTextColor(RGB(255, 255, 255));
>          pDC->SetBkColor(RGB(0, 0, 0));
>          hbr = ::CreateSolidBrush(RGB(0,0,0));
>          pDC->SetBkMode(TRANSPARENT);
>   }
>   return hbr;
>}


>> Hi,

>>    I need to color the background of a CStatic black (the text is white).
>> I'm overriding the
>> OnCtlColor method with the following :

>>   switch (nCtlColor) {
>>   case CTLCOLOR_STATIC:
>>     // Set the static text and background color
>>     pDC->SetTextColor(RGB(255, 255, 255));
>>     pDC->SetBkColor(RGB(0, 0, 0));
>>   default:
>>     return (HBRUSH)(m_pBkBrush->GetSafeHandle());
>>   }

>> The background color looks OK under the text that's printed (black bg white
>> text), but since the static control is sometimes wider than the text it
>> displays, the "left over" part remains white.  Also, sometimes the static
>> field has NO text in which case the whole thing is glaring white.

>> Any help is greatly appreciated.

>> Deanna

Joseph M. Newcomer

http://www3.pgh.net/~newcomer


Thu, 26 Apr 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Win2K: static background color vs. CFormView background color

2. Setting the background color of Static Text item and window

3. Changing the background color of a static text control

4. Background color for static text

5. static text background color

6. Newbie - Question About Text and Background Colors

7. Background Color, Text Color

8. Background color and text color in menu

9. Change text color and background color in CEditView

10. Change a part of Background color or a part of text color from CListCtrl

11. set the text color and the background color of a Control Cbutton

12. set text color on static text

 

 
Powered by phpBB® Forum Software