Solved

Fonts and colors in a CEdit

Posted on 1998-08-04
2
371 Views
Last Modified: 2013-12-02
How do you change the font, font color, and background color
of a CEdit control that has been placed on a view through code?

I have tried the function CWnd::SetFont() to no avail. When I do this nothing appears in the edit box when I type.

Thanks
0
Comment
Question by:lobrjos
2 Comments
 
LVL 11

Accepted Solution

by:
mikeblas earned 100 total points
ID: 1320207
If nothing appears in the Window, you've chosen a font that's too small to see, or you've destroyed the font after setting it and the control can't use it anymore.

You can set the foreground color and background color by handling WM_CTLCOLOR for the control. There's the foreground color, and you can set that by calling SetTextColor() on the CDC you get in the message.

The background color of the control comes in two parts: the background for the control where no text is painted, and the background of the text that is drawn into the control. Usually, you want those to be the same. If so, return a brush for the color you want in your CTLCOLOR handler and also call SetBkMode() to ask for a TRANSPARENT background mode.

If you want them to be different, set a OPAQUE background mode and return the brush for the control's background but set the text background with SetBkColor().

B ekiM
0
 

Author Comment

by:lobrjos
ID: 1320208
One thing to add about the answer to this question is that the WM_CTLCOLOR message to be handled by the control is a "reflection" message not the standard windows message.

Simply put, when you do using the class wizard in MFC you must use the WM_CTLCOLOR reflection message to add the handler (this is prefixed in the messages list of the class wizard dialog box with an = (i.e. =WM_CTLCOLOR not the WM_CTLCOLOR.

It took me a little while to figure this out.

Thanks for your help,

Joe
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now