• 0

[C++/Windows API] Edit Control characters not showing up


Question

I have a simple dialog box with an edit control. The following text, "迴辭駔駪餵騠駢馝", shows up in the title bar just fine, but shows up as partial blocks in the edit control. Unicode enabled. The font for the dialog box is MS Shell Dlg. The same font for an edit control in C# displays the same text just fine. VS 2010. I can't figure this one out. Any ideas?

Here's my code:

#include "resource.h"
#include <Windows.h>

#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' \
version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

INT_PTR WINAPI DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_INITDIALOG:
            SetDlgItemText(hDlg, IDC_EDIT1, L"迴辭駔駪餵騠駢馝");
            SetWindowText(hDlg, L"迴辭駔駪餵騠駢馝");
            break;
    case WM_COMMAND:
            if (wParam == IDOK) return EndDialog(hDlg, 0);
    }

    return 0;
}

int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR strCmdLine, int show)
{
    return DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), 0, DlgProc);
}

And the dialog:

IDD_DIALOG1 DIALOGEX 0, 0, 316, 183
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,205,162,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,259,162,50,14
    EDITTEXT        IDC_EDIT1,95,77,214,12,ES_AUTOHSCROLL
END

Here's the window:

post-51387-12828493406286.png

9 answers to this question

Recommended Posts

  • 0

And 10 minutes later, without modifying anything (on my computer or in Visual Studio), just recompiling:

post-51387-12832620829846.png

Edit: I've got an idea of what's going on: Visual Studio is saving the *.cpp files in some kind of funny format. Depending on the time of day (or something else that I can't figure out), the text gets encoded correctly or not.

  • 0

Yeah it's probably something like that. Store your strings in an external text file with the correct encoding and see if it fixes that.

  Quote
In addition to the letters of the English alphabet ("A" through "Z" and "a" through "z"), the digits ("0" through "9"), and the space, only the following characters are portable:

% & + , - . : = _

When naming files, variables, and other objects, only these characters should be considered for use.

https://www.securecoding.cert.org/confluence/display/cplusplus/MSC09-CPP.+Character+Encoding+-+Use+Subset+of+ASCII+for+Safety

This quite clearly applies to string literals.

  • 0

The point of this is not to develop secure coding practices or make a string-loading class. I'm simply interested in why a valid wide-character string is being displayed in an edit control incorrectly. I actually think it's an operating system problem now because after restarting my computer, the boxes are back. If I switch the Windows 7 display language to, say, German, and back to US English then things work fine. So it has something to do with how Windows is translating the text or mapping the dialog font. But according to MSDN, the MS Shell Dlg font and it's variant, which usually maps to Tahoma, should display the text correctly no matter what display language I'm using in Windows.

I'll try loading the string from a resource file to see what happens.

  • 0
  On 01/09/2010 at 19:31, boogerjones said:

I actually think it's an operating system problem now because after restarting my computer, the boxes are back. If I switch the Windows 7 display language to, say, German, and back to US English then things work fine.

Have you checked what it's mapping to on your system (HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes) when it's screwing up? It sounds like it might be mapping to a font that doesn't contain the characters, although with the one picture you have that shows both the boxes and correct characters, maybe not.

  On 01/09/2010 at 19:31, boogerjones said:

should display the text correctly no matter what display language I'm using in Windows.

Isn't it only designed to map to a font that can support the characters used in the currently selected language for non-unicode programs under the region and language control panel? I'm pretty sure this is Microsoft Sans Serif in most western languages.

Have you tried asking on the Microsoft forum? Maybe the UI development section?

  • 0

Thanks for your help, guys. Actually, I think my Windows installation was simply hosed. I'm somewhat embarrassed to admit that I had a ton of software installed on it for testing purposes, much of it in beta stages and some of it Visual Studio addins, and there was probably some conflict I'll never figure out. I zeroed my hard drive (to be sure), restored to a backup base Windows installation, installed Visual Studio, and now I haven't seen the problem again. It just seemed too weird of a problem to be related to my code.

How frustrating. But I guess that shows how important it is to be working with a clean system; you'll never know the cause of some strange phenomenon. I'll post back here if I still have trouble, but I think this was a case of Browser Toolbar Syndrome.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Toshiba's massive 22TB X300 PRO hard drive is 29% off by Taras Buria Toshiba is offering its highest-capacity X300 PRO hard drive at a new all-time low price, allowing you to save 29% or $171 on the massive 22TB drive. The X300 PRO hard drive lineup offers good performance, and it is rated for high yearly workloads, which makes it a great option for creative professionals or other tasks that require storing a lot of data. The X300 PRO is a 7,200 RPM conventional magnetic recording (CMR) 3.5-inch SATA 6Gbps internal hard drive with 512MB of cache, which is also paired with the Toshiba Cache Technology for improved real-time responsiveness during high-demand loads. It also has additional features for better reliability, such as ramp loading (heads rest to a side of platters to prevent damage when the drive is idling or powered down) and shock sensors. Toshiba claims that the 22TB X300 PRO is rated for up to a 300TB/year workload rate and 1 million hours of mean time to failure (MTTF). This makes the drive a good choice for workstations, multimedia systems, or network-attached storage. Additionally, each drive has a limited five-year warranty for additional peace of mind. 22TB Toshiba X300 PRO High Workload Performance HDD - $428.99 | 29% off on Amazon US This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • The 4060 is the weak 8-GB version. They should have done better.
    • This is an example of why it is so difficult to have a conversation with conservatives - they refuse to operate in good faith. You say "Those are not rights. Those were special treatments that were taken away that non-trans whatever didn't get." Which means you either failed to read any of the links I provided or you are lying. The very first link is about how the U.S. Military is firing trans people out of the military because they are trans and denying them retirement benefits. What other groups does the military treat this way that would support your assertion that they had been treated as special previously? Does the miliary routinely fire large numbers of its members and deny them retirement and was heretofore not doing that to trans people? I fail to see the logic in your argument.
  • Recent Achievements

    • One Month Later
      Jaclidio hoy earned a badge
      One Month Later
    • Week One Done
      Yawdee earned a badge
      Week One Done
    • Week One Done
      eugwalker earned a badge
      Week One Done
    • First Post
      Ben Gross earned a badge
      First Post
    • One Month Later
      chiptuning earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      636
    2. 2
      +FloatingFatMan
      178
    3. 3
      ATLien_0
      144
    4. 4
      Xenon
      120
    5. 5
      wakjak
      108
  • Tell a friend

    Love Neowin? Tell a friend!