Setting the background color of Static Text item and window 
Author Message
 Setting the background color of Static Text item and window

While designing ATL forms, I've encountered this problem, which seems
trivial at first glace.

I trying to make a the background of a static text transparent, or
paint it with a specific color (the form's background color), other
than the default gray.

I need this because I'm creating a form with a specific background
color. Actually, I couldn't find a way to do this other than creating
a huge bitmap (CreateCompatibleBitmap) and painting it with a
Rectangle of the same size.

I tried subclassing the WinProc (using SetWindowLong) so as to catch
and handle the WM_CTLCOLORSTATIC event, but it doesn't help - the
item's background is still gray. The same treatment _does_ work for
List Boxes using WM_CTLCOLORLISTBOX - which gets me to believe that
it's an ATL bug in Static Text.

Any idea? Also, I'll be glad to hear any idea regarding a simpler way
to set the window's background color.



Mon, 17 Feb 2003 03:00:00 GMT  
 Setting the background color of Static Text item and window

Can you add REFLECT_NOTIFICATIONS() macro and handle OCM_BASE +
WM_CTLCOLORSTATIC (??) Of course, You will have to check the handle (from
lparam).. Use the wParam (which is the HDC to set the background color
SettBkColor() .. It might help..

--
Girish Bharadwaj

Quote:

> While designing ATL forms, I've encountered this problem, which seems
> trivial at first glace.

> I trying to make a the background of a static text transparent, or
> paint it with a specific color (the form's background color), other
> than the default gray.

> I need this because I'm creating a form with a specific background
> color. Actually, I couldn't find a way to do this other than creating
> a huge bitmap (CreateCompatibleBitmap) and painting it with a
> Rectangle of the same size.

> I tried subclassing the WinProc (using SetWindowLong) so as to catch
> and handle the WM_CTLCOLORSTATIC event, but it doesn't help - the
> item's background is still gray. The same treatment _does_ work for
> List Boxes using WM_CTLCOLORLISTBOX - which gets me to believe that
> it's an ATL bug in Static Text.

> Any idea? Also, I'll be glad to hear any idea regarding a simpler way
> to set the window's background color.



Mon, 17 Feb 2003 03:00:00 GMT  
 Setting the background color of Static Text item and window

SetBkColor won't work. One has to return a brush handle of proper color in
response to WM_CTLCOLOR* messages. SetTextColor does work if you want to
change the font color.
--
With best wishes,
    Igor Tandetnik


Quote:
> Can you add REFLECT_NOTIFICATIONS() macro and handle OCM_BASE +
> WM_CTLCOLORSTATIC (??) Of course, You will have to check the handle (from
> lparam).. Use the wParam (which is the HDC to set the background color
> SettBkColor() .. It might help..

> --
> Girish Bharadwaj


> > While designing ATL forms, I've encountered this problem, which seems
> > trivial at first glace.

> > I trying to make a the background of a static text transparent, or
> > paint it with a specific color (the form's background color), other
> > than the default gray.

> > I need this because I'm creating a form with a specific background
> > color. Actually, I couldn't find a way to do this other than creating
> > a huge bitmap (CreateCompatibleBitmap) and painting it with a
> > Rectangle of the same size.

> > I tried subclassing the WinProc (using SetWindowLong) so as to catch
> > and handle the WM_CTLCOLORSTATIC event, but it doesn't help - the
> > item's background is still gray. The same treatment _does_ work for
> > List Boxes using WM_CTLCOLORLISTBOX - which gets me to believe that
> > it's an ATL bug in Static Text.

> > Any idea? Also, I'll be glad to hear any idea regarding a simpler way
> > to set the window's background color.



Mon, 17 Feb 2003 21:24:44 GMT  
 Setting the background color of Static Text item and window

You are right. It does not work!! But, If you handle the WM_CTLCOLOR on the
dialog window itself, it might work. It does work for MFC.. I cant see why
it should not work for ATL..

--
Girish Bharadwaj

Quote:
> SetBkColor won't work. One has to return a brush handle of proper color in
> response to WM_CTLCOLOR* messages. SetTextColor does work if you want to
> change the font color.
> --
> With best wishes,
>     Igor Tandetnik



> > Can you add REFLECT_NOTIFICATIONS() macro and handle OCM_BASE +
> > WM_CTLCOLORSTATIC (??) Of course, You will have to check the handle
(from
> > lparam).. Use the wParam (which is the HDC to set the background color
> > SettBkColor() .. It might help..

> > --
> > Girish Bharadwaj


> > > While designing ATL forms, I've encountered this problem, which seems
> > > trivial at first glace.

> > > I trying to make a the background of a static text transparent, or
> > > paint it with a specific color (the form's background color), other
> > > than the default gray.

> > > I need this because I'm creating a form with a specific background
> > > color. Actually, I couldn't find a way to do this other than creating
> > > a huge bitmap (CreateCompatibleBitmap) and painting it with a
> > > Rectangle of the same size.

> > > I tried subclassing the WinProc (using SetWindowLong) so as to catch
> > > and handle the WM_CTLCOLORSTATIC event, but it doesn't help - the
> > > item's background is still gray. The same treatment _does_ work for
> > > List Boxes using WM_CTLCOLORLISTBOX - which gets me to believe that
> > > it's an ATL bug in Static Text.

> > > Any idea? Also, I'll be glad to hear any idea regarding a simpler way
> > > to set the window's background color.



Mon, 17 Feb 2003 22:56:21 GMT  
 Setting the background color of Static Text item and window
You may be able to  subclass it and handle the WM_ERASEBKGND message
explicitly... I haven't actually tried it myself...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:

> While designing ATL forms, I've encountered this problem, which seems
> trivial at first glace.

> I trying to make a the background of a static text transparent, or
> paint it with a specific color (the form's background color), other
> than the default gray.

> I need this because I'm creating a form with a specific background
> color. Actually, I couldn't find a way to do this other than creating
> a huge bitmap (CreateCompatibleBitmap) and painting it with a
> Rectangle of the same size.

> I tried subclassing the WinProc (using SetWindowLong) so as to catch
> and handle the WM_CTLCOLORSTATIC event, but it doesn't help - the
> item's background is still gray. The same treatment _does_ work for
> List Boxes using WM_CTLCOLORLISTBOX - which gets me to believe that
> it's an ATL bug in Static Text.

> Any idea? Also, I'll be glad to hear any idea regarding a simpler way
> to set the window's background color.



Tue, 18 Feb 2003 10:01:06 GMT  
 Setting the background color of Static Text item and window

On Thu, 31 Aug 2000 10:56:21 -0400, "Girish Bharadwaj"

Quote:

>You are right. It does not work!! But, If you handle the WM_CTLCOLOR on the
>dialog window itself, it might work. It does work for MFC.. I cant see why
>it should not work for ATL..

Igor, as I mentioned in the original posting, WM_CTLCOLOR* doesn't
work for Static Text.

Girish, I didn't try to handle the WM_CTLCOLOR of the dialog window
itself. Worth the try. Thanks.



Thu, 20 Feb 2003 16:46:39 GMT  
 Setting the background color of Static Text item and window

WM_CTLCOLOR* is sent to the parent window of the control (as is plainly
stated in the documentation). You tried to handle it by subclassing the
control, which was a wrong thing to do. Handle it in the dailog window.
--
With best wishes,
    Igor Tandetnik


Quote:
> On Thu, 31 Aug 2000 10:56:21 -0400, "Girish Bharadwaj"

> >You are right. It does not work!! But, If you handle the WM_CTLCOLOR on
the
> >dialog window itself, it might work. It does work for MFC.. I cant see
why
> >it should not work for ATL..

> Igor, as I mentioned in the original posting, WM_CTLCOLOR* doesn't
> work for Static Text.

> Girish, I didn't try to handle the WM_CTLCOLOR of the dialog window
> itself. Worth the try. Thanks.



Sat, 22 Feb 2003 23:48:02 GMT  
 
 [ 7 post ] 

 Relevant Pages 

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

2. set text color on static text

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

4. Changing the background color of a static text control

5. Background color for static text

6. Static text background color question

7. static text background color

8. setting text and background colors for a control

9. Setting background & text color

10. Setting text and background color in CEdit

11. how to set text background color

12. set text color for an item

 

 
Powered by phpBB® Forum Software