Solved

Fonts and colors in a CEdit

Posted on 1998-08-04
2
370 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…

760 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

17 Experts available now in Live!

Get 1:1 Help Now