Setting the background color of Static Text item and window
Author |
Message |
Tal R #1 / 7
|
 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 |
|
 |
Girish Bharadwa #2 / 7
|
 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 |
|
 |
Igor Tandetni #3 / 7
|
 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 |
|
 |
Girish Bharadwa #4 / 7
|
 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 |
|
 |
Alexander Nickolo #5 / 7
|
 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 |
|
 |
Tal R #6 / 7
|
 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 |
|
 |
Igor Tandetni #7 / 7
|
 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 |
|
|
|