• 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

    • Microsoft Store is getting improved recommendations, deeper Windows integration, and more by Taras Buria Microsoft announced several new features coming to the Microsoft Store on Windows 11. The company revealed that 250 million customers use the Microsoft Store each month. With the latest updates, Microsoft is improving the experience with better recommendations, search improvements, deeper Windows integration, Copilot, and more. The store's Home Page is getting personalized recommendations with suggestions based on your recent activities, what is trending in your region, and the recent deals. Microsoft says this change will bring more meaningful and relevant content. Search is getting smarter, and it now uses additional information when ranking apps. It is "intent-aware," and considers additional aspects like app updates, ratings, language-specific nuances, and more. In the United States, the Microsoft Store now has a Copilot button at the bottom of the screen. Clicking it lets you ask questions about an app or game, or compare two products. Speaking of Copilot, apps with AI-powered experiences now have a badge indicating that certain apps work better on Copilot+ PCs. Other changes to the Microsoft Store include a new Discover More section with related apps and deeper Windows integration. The latter lets you find apps in the Microsoft Store using Windows Search, and the "Open With" dialog now includes additional recommendations from the Microsoft Store. Finally, Microsoft made multiple under-the-hood improvements to boost performance (the app launches twice as fast as it did six months ago) and improve installation reliability. In addition to new features coming to the Microsoft Store, the company reminded users that some popular productivity apps are now available in the Store. They include Notion, Perplexity, Docker, and Day One. You can read more about all those changes in a post on the official Windows Blogs website. Last month, at Build 2025, Microsoft announced more improvements for the Microsoft Store, so stay tuned for those.
    • OpenAI exposes secret propaganda campaigns tied to multiple countries by David Uzondu Back in February, OpenAI shut down accounts that were busy developing Chinese surveillance tools aimed at the West. These tools were designed to snoop on social media, look for anti-China sentiment and protests, and report back to Chinese authorities. Now, OpenAI has announced it has disrupted even more shady operations, and not just those tied to China. In a report released Thursday, the company detailed how it recently dismantled ten different operations that were misusing its artificial intelligence tools. One of the China-linked groups, which OpenAI called "Sneer Review," used ChatGPT to churn out short comments for sites like TikTok, X, and Facebook. The topics varied, from U.S. politics to criticism of a Taiwanese game, where players work against the Chinese Communist Party. This operation even generated posts and then replied to its own posts to fake real discussions. What is particularly interesting is that the group also used ChatGPT to write internal performance reviews, describing how well they were running their influence campaign. Another operation with ties to China involved individuals posing as journalists and geopolitical analysts. They used ChatGPT to write social media posts and biographies for their fake accounts on X, translate messages from Chinese to English, and analyze data. OpenAI mentioned that this group even analyzed correspondence addressed to a U.S. Senator. On top of that, these actors used OpenAI's models to create marketing materials, basically advertising their services for running fake social media campaigns and recruiting intelligence sources. OpenAI also disrupted operations, probably originating in Russia and Iran. There was also a spam operation from a marketing company in the Philippines, a recruitment scam linked to Cambodia, and a deceptive job campaign that looked like something North Korea might orchestrate. Ben Nimmo, from OpenAI's intelligence team, noted the wide range of tactics and platforms these groups are using. However, he also said these operations were mostly caught early and did not manage to fool large numbers of real people. According to Nimmo, "We didn't generally see these operations getting more engagement because of their use of AI. For these operations, better tools don't necessarily mean better outcomes."
    • Long ago, I was in a networking class on a lab computer. The guy next to sarcastically told me to SHIFT+DELETE the C:\Windows folder. I said that I was sure Windows wouldn't allow such a thing (Windows 2000), and would either totally block the action or give some kind of dire warning. I was so confident that I tried it...not only was I wrong, but it didn't even give the standard "are you sure" warning, just went to town. I pressed cancel as quick as I could, but it was too late, shortly after, the system blue-screened and never booted again. I had to stay late and reinstall Windows for the teacher, but that ended up being a good thing, had great repour with him for the rest of the year, even got to help him get Active Directory setup in his lab.
    • My best decision: SHIFT+DELETE WINDOWS Then Installed Fedora Linux. Now I am a Happy Person
  • Recent Achievements

    • One Year In
      survivor303 earned a badge
      One Year In
    • Week One Done
      jbatch earned a badge
      Week One Done
    • First Post
      Yianis earned a badge
      First Post
    • Rookie
      GTRoberts went up a rank
      Rookie
    • First Post
      James courage Tabla earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      419
    2. 2
      snowy owl
      182
    3. 3
      +FloatingFatMan
      182
    4. 4
      ATLien_0
      176
    5. 5
      Xenon
      136
  • Tell a friend

    Love Neowin? Tell a friend!