Solved

Font problems in a CRichEditCtrl

Posted on 1997-11-22
3
1,094 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
  • 2
3 Comments
 

Author Comment

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

Accepted Solution

by:
mikeblas earned 200 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

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

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 85
Font that uses "minimal ink" when printing 27 59
dog bark java program 15 87
haveThree challenge 22 114
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 …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…

910 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

24 Experts available now in Live!

Get 1:1 Help Now