Madz
Madz

Reputation: 1279

Superscript 4 not showing up in MFC dialog

So I'm trying to print lbf.S²/in⁴ in a mfc label, but it shows-up as lbf.S²/in4.

I'm wondering why ² will display correctly while wouldn't. It's a 32bit project with Unicode character set.

Here's the .rc code

STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Units"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
    CTEXT           "lbf-sec²/ in⁴",IDC_IPS1,77,36,48,8
END

Upvotes: 3

Views: 417

Answers (2)

acraig5075
acraig5075

Reputation: 10756

I'm convinced this has to do with inadvertent changes to the file encoding.

Recreate as follows:

  1. New dialog based solution.
  2. Paste lbf-sec²/ in⁴ as static text caption
  3. Build and run, and all is well.

    enter image description here enter image description here

  4. Open .rc file in Sublime Text editor and try change encoding to Windows-1252. (This is just to try mimic the inadvertent change that Visual Studio somehow can do.)
  5. Characters are not representable and it falls back to UTF-8 encoding enter image description here
  6. Save
  7. Visual Studio now refreshes and caption is garbled.

    enter image description here

  8. Paste again lbf-sec²/ in⁴ as the label caption
  9. Build and run, and you see the error

    enter image description here

  10. View .rc file in editor and text has indeed reverted and so has encoding

    enter image description here

Caveat

I'm not saying I know how, why or when the encoding changes, I'm saying it somehow can happen.

A solution (What works for me)

  1. Close Visual Studio
  2. Save .rc file still with incorrect lbf-sec²/ in4, and with encoding UTF-8
  3. Open Visual Studio
  4. Edit the caption to the correct lbf-sec²/ in⁴
  5. Use context menu in Resource View to save .rc file (don't know if necessary)
  6. Close dialog editor window (don't know if necessary)
  7. Clean, Rebuild All, run and all is well.

    enter image description here


If I knew how to clear whatever cache the dialog editor uses, then I'd say that would be closer to the actual solution.

Upvotes: 2

Adrian Mole
Adrian Mole

Reputation: 51874

It would appear that the font you have selected for your dialog box doesn't support the superscript 4 and the character is being mapped to the plain 4. (Many fonts have the superscript 2, as yours does, but other superscript characters are not so widely supported.)

In your resource script, make sure you have a font that includes all characters you want to use (Arial Unicode MS has pretty much everything you're likely to use, and is installed on most Windows systems, IIRC), and be sure to include the DS_SETFONT style:

IDD_MYBOX   DIALOGEX    0, 0, 370, 270                                                                   // 14-JAN-2020
STYLE       DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION     L"My Dialog Box Title"
FONT        10, L"Arial Unicode MS"
{
    //.. dialog controls
}

Alternatively, you can explicitly set the font for a given control, but that's a bit more work, as you have to define and load the font into your executable at run-time (I can help you with some code to do this, if you want to go down that path.)

Other fonts that have a good selection of superscript numbers include "Calibri" (my favourite for UIs) and "Arial," but I'm not sure what the licencing and redistribution arrangements for these are.

Upvotes: 1

Related Questions