
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