Dipthong
Dipthong

Reputation: 282

CEdit does not display special characters

Why does CEdit control not display special characters e.g., ™ (Trademark)? For example, create a CDialog with a CEdit control and set the Dialog title and CEdit control to the same CString and get different results.

CString  s(_T("ShowTM ™"));
SetWindowText(s);           //Set Dialog Title (shows ™)
editCtrl.SetWindowText(s);  //Set Edit Control (does not show ™)

What the Dialog looks like

Upvotes: 4

Views: 1862

Answers (3)

Dipthong
Dipthong

Reputation: 282

Thanks Christian and Paul. With your help I was able to piece together what was going on. The conclusion may be flawed but Visual Studio use to create dialogs with a default font property of

FONT 8, "MS Sans Serif"

MS Sans Serif is only really used by Windows Me/95/98 and is missing the characters I needed.

Today the default font is

FONT 8, "MS Shell Dlg"

MS Shell Dlg is not really a font as much as a placeholder Windows maps on to a real font later, depending on the version of Windows. Windows XP/Vista/7 etc map to Microsoft (not MS) Sans Serif which has the characters I needed.

I believe Windows was dynamically mapping MS Sans Serif to Microsoft Sans Serif for CDialog, but not CEdit, and

editCtrl.SetWindowTextW( _T("Hello ™"));

worked because new dialogs use MS Shell Dlg font and therefore get the full character set of Microsoft Sans Serif.

Given this is legacy code I have just under 200 explicit MS San Serif references that should be update to MS Shell Dlg. Yay!

For more detail on the font mapping see https://msdn.microsoft.com/en-us/library/windows/desktop/dd374112%28v=vs.85%29.aspx.

Upvotes: 3

TheUndeadFish
TheUndeadFish

Reputation: 8171

One good test when diagnosing this kind of stuff is to try copying the text out of the running app and pasting it into a decent Unicode-compatible text editor.

If that ends up showing the symbol intact, then you have a font / rendering kind of problem.

In this case, your problem is MS San Serif itself. Simply put, it sucks. For some reason it seems to have black boxes for certain special characters. So that font is intentionally rendering them that way.

Here are a couple screenshots using little app I once made for testing characters and fonts.

Arial:

enter image description here

And the same in MS Sans Serif:

enter image description here

Notice the TM symbol among others is a box.

So the solution is: Don't use MS Sans Serif.

Now, why isn't the title bar affected when your CDialog is using MS Sans Serif? Because the dialog's font affects the rendering of the rest of the text in the client area, not the caption of the window. (Actually I'm not sure you can even affect the caption's font without taking over its rendering entirely. Otherwise it using what's specified by the system/personalization/theme/whatever settings.)

Upvotes: 2

Christian Abella
Christian Abella

Reputation: 5797

Use SetWindowTextW instead of SetWindowText so that the Unicode can be processed.

editCtrl.SetWindowTextW( _T("Hello ™"));

enter image description here

Upvotes: 1

Related Questions