Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Fonts and colors in a CEdit

Posted on 1998-08-04
2
Medium Priority
?
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

715 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