Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Fonts and colors in a CEdit

Posted on 1998-08-04
2
Medium Priority
?
384 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 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

916 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