CEdit does not display special characters

Why isn't the CEdit control displaying special characters such as ™ (trademark)? For example, create a CDialog with a CEdit control and set the Dialog and CEdit title 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

+3


source to share


3 answers


Thanks to Christian and Pavel. With your help, I was able to piece together what was happening. The output might be wrong, but Visual Studio uses to create dialogs with a standard font property

FONT 8, "MS Sans Serif"

      

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

Default font today

FONT 8, "MS Shell Dlg"

      

MS Shell Dlg is not actually a font, as the placeholder instead of Windows is now mapped to a real font depending on the version of Windows. Windows XP / Vista / 7, etc. Microsoft card (not MS). Sans serifs that have the characters I want.



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

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

      

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

Given this obsolete code, I only have 200 explicit MS San Serif references that need to be updated to MS Shell Dlg. Hooray!

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

+3


source


One good test when diagnosing this sort of thing is to try and copy text from a running application and paste it into a decent Unicode-compatible text editor.

If it ends up not being corrupted then you have a font / rendering issue.

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

Here are some screenshots using a small application I once made to test symbols and fonts.

Arial:

enter image description here



And the same in MS Sans Serif:

enter image description here

Note that the TM symbol among others is a field.

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

Now why isn't the header affected when your CDialog uses MS Sans Serif? Because the dialog font affects the rendering of the rest of the text in the client area, not the title of the window. (Actually I'm not sure if you can even influence the font caption without intercepting its rendering entirely. Otherwise, it uses what is specified in the system / personalization / theme / whatever options.)

+2


source


Use SetWindowTextW

instead SetWindowText

so that Unicode can be processed.

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

      

enter image description here

+1


source







All Articles