
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