Change background color of disabled CEdit controls 
Author Message
 Change background color of disabled CEdit controls

Hello,

Can someone tell me if there is a way to change the background and character
collor of a disabled CEdit control. (The gray characters on a gray
background are not always readable) I look rather to change the property of
the CEdit control than getting a DC for every control and repainting my
controls.

Greatings
Jean Paul



Wed, 09 Apr 2003 03:00:00 GMT  
 Change background color of disabled CEdit controls

Quote:
>Can someone tell me if there is a way to change the background and character
>collor of a disabled CEdit control. (The gray characters on a gray
>background are not always readable) I look rather to change the property of
>the CEdit control than getting a DC for every control and repainting my
>controls.

Jean Paul,

I think you'll need to handle the WM_CTLCOLOR (CTLCOLOR_STATIC)
message for a disabled edit control.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Wed, 09 Apr 2003 03:00:00 GMT  
 Change background color of disabled CEdit controls



Quote:
> Can someone tell me if there is a way to change the background and character
> collor of a disabled CEdit control. (The gray characters on a gray
> background are not always readable) I look rather to change the property of
> the CEdit control than getting a DC for every control and repainting my
> controls.

Well, yes and no. The appearance of something like a disabled edit box is system defined. This
allows the user to use a desktop themes package (like the one in Microsoft Plus!) to define how each
visual element should look on their system. Your application is then supposed to use these system
defined colors.

You can use the OnCtlColor() event to tell the OS to use different colors for a specific window, but
for a disabled edit box the OS will ignore the text color you return and use the system color
COLOR_GRAYTEXT instead. It will use the background and text background colors though, so you could
lighten the background instead of darkening the text to get a better contrast.

However, this is a system incompatible hack and you really should stick with whatever colors the
user has defined for the system to stay compatible with the OS accessibility features. For some
visually impaired folks, like me, the font colors, types, and sizes we choose for the system are
very important to our ability to use the applications effectively.

The disabled flag is intended to be used for an edit box that should not be selected, read, or
written. If what you actually want is to just disable the write or edit ability, but allow the user
to read, select, or copy the contents, then what you want to use is the SetReadOnly() method which
sets the ES_READONLY flag on the edit box. This will still gray the background, but it will use the
normal text color and the user can select and copy the contents.

There are some application developers that do not like the gray background of the readonly edit box.
What they do is to use the OnCtlColor() event to change the color of any readonly edit box in their
application to a normal window background (COLOR_WINDOW) and the disabled color for the text
(COLOR_GRAYTEXT). This creates less of a visual discontinuity when the edit box changes state but
still clearly indicates the current state.

--
The Snake Pit - Development

Proprietor



Wed, 09 Apr 2003 03:00:00 GMT  
 Change background color of disabled CEdit controls

Quote:

>Can someone tell me if there is a way to change the background and character
>collor of a disabled CEdit control. (The gray characters on a gray
>background are not always readable) I look rather to change the property of
>the CEdit control than getting a DC for every control and repainting my
>controls.

Davids solution is (of course) correct : if you want sample code for
doing this, there's some on my web site at the url below:

www.mooremvp.freeserve.co.uk/Win32/w32tip45.htm

--
Bob Moore [WinSDK MVP]
http://www.mooremvp.freeserve.co.uk/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Do not reply via email unless specifically requested to do so.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Thu, 10 Apr 2003 03:00:00 GMT  
 Change background color of disabled CEdit controls


Fri, 19 Jun 1992 00:00:00 GMT  
 Change background color of disabled CEdit controls

Dear Mr. Bob,

I tested your nice code at
[http://www.mooremvp.freeserve.co.uk/Win32/w32tip11.htm]
to draw a background bitmap.

But it does not work. I mean, the dialog never call any OnEraseBkgnd at all, and
when I call this method my self from the OnInitDlg, also nothing occures!!!

Could you please explain it to me? It is very important for me.

Please make a cc to my Email.

Regards

Tarek

Quote:


> >Can someone tell me if there is a way to change the background and character
> >collor of a disabled CEdit control. (The gray characters on a gray
> >background are not always readable) I look rather to change the property of
> >the CEdit control than getting a DC for every control and repainting my
> >controls.

> Davids solution is (of course) correct : if you want sample code for
> doing this, there's some on my web site at the url below:

> www.mooremvp.freeserve.co.uk/Win32/w32tip45.htm

> --
> Bob Moore [WinSDK MVP]
> http://www.mooremvp.freeserve.co.uk/
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> Do not reply via email unless specifically requested to do so.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Fri, 11 Apr 2003 03:00:00 GMT  
 Change background color of disabled CEdit controls

Quote:

>But it does not work. I mean, the dialog never call any OnEraseBkgnd at all,

ClassWizard is hiding this from you (remember, a dialog is just
another window). In order to create a handler for this message you
have to stop ClassWizard from filtering the messages it presents.

Launch ClassWizard, select your dialog class and click the "Class
Info" tab. At the bottom of that tab you will find a combo marked
"message filter". In that combo, select "Window". Then go back to the
Message Map and you'll find you can create a handler for the
WM_ERASEBKGND message, which is where my code goes.

Just calling the code on the fly won't work because windows will
promptly undo the effect when it repaints. You must create a handler
as described above.

When I get a moment, I'll modify the code tip to make this clearer.

--
Bob Moore [WinSDK MVP]
http://www.mooremvp.freeserve.co.uk/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Do not reply via email unless specifically requested to do so.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Fri, 11 Apr 2003 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Changing the default background color of disabled control (CEdit)

2. How to change background color of a dynamically created CEdit control

3. Changing the Background Color of Individual CEdit controls in a CDialogBar

4. Changing color of background of a CEdit control

5. How to change background color of a disabled edit control

6. Changing background color for disabled edit controls

7. Changing background color of disabled edit controls

8. Changing background color of disabled edit control

9. Changing Background Color of CEdit - Problem With Double Clicking On Texts

10. How to change background color Of CEdit?

11. How to change background color of CEdit?

12. Changing CEdit background COLOR on FOCUS????

 

 
Powered by phpBB® Forum Software