Jump to content
Sign in to follow this  

Setting the font programmatically (in Rich Edit)

Recommended Posts


I am working on making the Rich Edit UDFs as easy to use as possible. At this time, I am working on a UDF for the EM_SETCHARFORMAT, SCF_SELECTION, BitOR(CFM_FACE,CFM_SIZE) combination

MSDN says for the SETCHARFORMAT message that setting wParam to SCF_ASSOCIATEFONT requires that the following members of CHARFORMAT2 be set: yHeight, bCharSet, bPitchAndFamily, szFaceName and Lcid. This will "associate a font with a script". They say much less about SCF_SELECTION.

My objectives are:

  • if a parameter can be looked up by Windows, don't make it a parameter to a UDF function.
  • if a user calls a UDF with an illegal combination of parameters, set @error
  • reduce the number of parameters to the minimum required to provide full functionality of Rich Edit
  • document adequately
From MSDN, I gather that to associate a font with a script, the syntax might be GuiCtrlRichEdit_SetAssociateFont($iyHeight, $ibCharSet, $ibPitch, $ibFamily, $szFaceName, $iLcid) but is there an easier way? (I assume that GuiCtrlRichEdit_SetFont might require the same parameters.)

I recognize that the user would need to enter some parameters:

  • szFaceName - "Courier", "Arial", "Times Roman", etc. - but not "Courier Bold" - colloquially called Font
  • yHeight - renamed Points: yHeight = Points * 20
Does he need to enter bFamily and bPitch? Or can Windows determine them from szFontFace? If so, how programmatically?

LCid (Locale ID): In Control Panel | Regional Options | Input Locales, Locales are set. Is there a way of checking that the user enters one of the locales set in Control Panel? Might be validly wish to use another locale?

bFamily and bPitch: It seems to me that these are inherently set by specifying szFaceName, so they probably don't need to be entered. Am I correct? How can they be determined programmatically from szFaceName?


  • Are only certain character sets available to a user who has set particular Locales? e.g. If the Locale is English - United States, is setting bCharSet to GREEK_CHARSET invalid? Or should @extended be set to "Strange character set!" to warn the user?
  • It seems to me that a typeface may only support certain character sets, e.g. Courier may not support VIETNAMESE_CHARSET. How can this be detected programmatically?
How can the UDF check that values entered for parameters are valid?

In summary, can setting the font and size of a selection (or at the insertion point) be done with just GuiCtrlRichEdit_SetFont($szFaceName, $iPoints) or is more required? This is not working for me at the moment. Is this because there are bugs in my code? Should some parameters be optional?


A (limited) example:

I am in Canada, so my locales are English - Canada (default) and French - Canada. I wish to write the following in a Rich Edit control:

A commentator in Montreal says that doulos means slave

I code GuiCtrl_RichEdit("Aerial" ... . How do I get the UDF to set @error?

Montreal has an accent on the "e". Arial probably supports the French character set, so does _SetFont need to just change the character set? Can this change be transparent to the user?

Doulos is a Greek word, so I wish to show it in Greek characters. I download a font called Greek Trad. But my computer doesn't have a Greek locale. Is it possible for me to display the word in Greek characters, and if so, what parameters does _SetFont need to have to do it? I note that MSDN doesn't mention CFE_ constants for setting character set and locale ID.

Edited by c.haslam


CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this