Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Font problems in a CRichEditCtrl

Posted on 1997-11-22
3
Medium Priority
?
1,169 Views
Last Modified: 2013-12-02
I am having trouble changing the font in a CRichEditCtrl (created as a child window).  When I tried to use the CRichEditControl's SetDefaultCharFormat() function, no matter what I did to it, the font always remained at an 8 point system font (I *was* setting the mask).  Next I tried to use the window's SetFont() function to set the font.  Now here comes the weird part:

When I use the SetFont() function before I use SetDefualtCharFormat() (which I am still using for other details, such as color) AND I have the mask's CFM_SIZE flag set, then SetFont correctly changes the font to what I defined.  However, there are some weird things that happen in this situation.  Mainly, if I use GetDefaultCharFormat() again, the font name is correct in the structure, but the yHeight variable is some huge number (eg. with a 9 point Arial font the yHeight is 105, with 20 point it is 255).  I am not sure if there is a relation between the two at all, but I assume since it changes with it, that there is.

On the other hand, if I do not set the CFM_SIZE flag, or I call SetDefaultCharFormat() with the other changes (color, etc.) the font point seems to be extremely offset by something (9 point font is barely legible, 15 point is about the size 9 should be).

This problem has been bugging me for about a week now, and I can find no answers on newsgroups or other message boards.  Along with this I would like to ask what the formula is (if there is one) for obtaining the size the edit box should be to allow full space for all the chars (plus a couple pixels above and below).  Please help.

- prodos
0
Comment
Question by:prodos
[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
3 Comments
 

Author Comment

by:prodos
ID: 1310563
Adjusted points to 150
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 800 total points
ID: 1310564
You shouldn't use SetFont().

This code works fine for me when setting the default character format on a rich edit control:

      CHARFORMAT cfm;
      cfm.cbSize = sizeof(cfm);
      cfm.dwMask = CFM_FACE | CFM_SIZE;
      cfm.yHeight = 240;
      lstrcpy(cfm.szFaceName, "Arial");

      CRichEditCtrl* pCtrl = (CRichEditCtrl*) GetDlgItem(IDC_RICHEDIT1);
      VERIFY(pCtrl->SetDefaultCharFormat(cfm));

The value in yHeight is in twips.  There's 20 twips in a point. 240, which I used above, is 12 points.

Why didn't you look at the WORDPAD sample that ships with VC++, by the way?

You ask two questions, so I guess I have to answer the second one for free: you'll find that setting the window height of the edit control to 1.5 times the cell height of the characters you're using is most pleasing to the eye.  Don't mulitply by 1.5; do something sensible with integers, like this:

   int nHeight = /* initialized someplace else */;
   int nSize = nHeight + nHeight/2;

.B ekiM


0
 

Author Comment

by:prodos
ID: 1310565
Adjusted points to 200
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…
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…

610 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