4

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

Dipthong
  • 262
  • 3
  • 13
  • 1
    More than likely the edit control is using a different font than the title, and the codepoint used for the trademark symbol does not exist in the edit control's font. – PaulMcKenzie May 12 '15 at 22:04
  • Thanks for the reply Paul. I checked and the CDialog and CEdit both use "MS Sans Serif". Although, oddly, I could not find the TM char when viewing the font in Windows 7 character map utility. – Dipthong May 12 '15 at 22:56
  • See https://stackoverflow.com/a/73032811/232175 if you see a "T" instead of a TM sign – Matthias Jul 19 '22 at 08:11

3 Answers3

3

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.

Dipthong
  • 262
  • 3
  • 13
2

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.)

TheUndeadFish
  • 8,058
  • 1
  • 23
  • 17
  • I think font for dialog title bar is "Segoe UI" size 9. This is the default font for Window Vista and higher. I don't really know what is happening but try changing dialog's default font to Segoe UI. – Barmak Shemirani May 13 '15 at 00:20
1

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

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

enter image description here

Christian Abella
  • 5,747
  • 2
  • 30
  • 42
  • Thanks for the reply Christian. I tried this method and still get the same result. Which is no surprise since if I step into SetWindowTextW it redirects back to SetWindowText. I suspect this is Unicode related I just can't nail down how. – Dipthong May 12 '15 at 23:02
  • it is displaying properly in my side. what Visual Studio version are you using? – Christian Abella May 12 '15 at 23:05
  • I have attached the screenshot of my application here. – Christian Abella May 12 '15 at 23:08
  • 1
    Your window is not created as a Unicode window with CreateWindowW... so your window uses MSBC internally. So SetWindowTextW alone will not work... – xMRi May 13 '15 at 06:35