Setting background & text color 
Author Message
 Setting background & text color

I have several text boxes that are on a CFormVeiw type
window (as opposed to a CDialog type window). I cannot
change the text color or background color for the text
boxes using the OnCtlColor method. I took out all the case
statements looking for cases such as CTLCOLOR_DLG, just to
make sure that the code gets called.  Here is the code
being executed:

HBRUSH CMyClass::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
nCtlColor)
{
   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
   pDC->SetTextColor(COLOR_WHITE);
   pDC->SetBkColor(COLOR_BLACK);
   hbr = pApp->brush.black;
   return hbr;

Quote:
}

I have run this through the de{*filter*} and it is making it
through here.  However, the color never changes.

Are regular text boxes (of type CWnd) incompatitible with
the CFormView class?  When I have a CListControl component,
I can change the color with no problem.

Thanks



Sun, 05 Jun 2005 23:06:52 GMT  
 Setting background & text color
I tend to move this sort of thing into the control itself, by subclassing the control and
using =WM_CTLCOLOR.

I don't see anything here that limits the changes to CTLCOLOR_STATIC or CTLCOLOR_EDIT
(depending on what you mean by "text boxes"). Are you sure this method is being called? It
looks fine to me, in terms of what it is supposed to do (but it does it to every control
in the dialog).

"Regular" text boxes don't exist--I've never heard the term. There are CStatic-derived
controls, and CEdit-derived controls. Both can hold text. Both are subclasses of CWnd.
They are both compatible with OnCtlColor. OTOH, if you created a control that is directly
derived from CWnd, it is YOUR responsibility with respect to that control to determine the
color; there is no automatic mechanism for other than the built-in controls to request the
parent to supply the color.
                                joe

Quote:

>I have several text boxes that are on a CFormVeiw type
>window (as opposed to a CDialog type window). I cannot
>change the text color or background color for the text
>boxes using the OnCtlColor method. I took out all the case
>statements looking for cases such as CTLCOLOR_DLG, just to
>make sure that the code gets called.  Here is the code
>being executed:

>HBRUSH CMyClass::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
>nCtlColor)
>{
>   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
>   pDC->SetTextColor(COLOR_WHITE);
>   pDC->SetBkColor(COLOR_BLACK);
>   hbr = pApp->brush.black;
>   return hbr;
>}

>I have run this through the de{*filter*} and it is making it
>through here.  However, the color never changes.

>Are regular text boxes (of type CWnd) incompatitible with
>the CFormView class?  When I have a CListControl component,
>I can change the color with no problem.

>Thanks

Joseph M. Newcomer [MVP]

Web: http://www.*-*-*.com/ ~newcomer
MVP Tips: http://www.*-*-*.com/ ~newcomer/mvp_tips.htm


Mon, 06 Jun 2005 00:05:47 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How can we set BackGround & Text color in a ListBox with VC+?

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

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

4. setting text and background colors for a control

5. Setting text and background color in CEdit

6. how to set text background color

7. Background & Text color CEdit

8. Background Color, Text Color

9. Background color and text color in menu

10. Change text color and background color in CEditView

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

12. CEditView Background Color & Font Color :: MFC

 

 
Powered by phpBB® Forum Software