c++ - 如何确保在 Windows 10 上将数字呈现为阿拉伯数字?

标签 c++ winapi numbers windows-10

我的应用程序允许用户通过选择用户首选语言来自定义 UI。它通常工作得很好,除了在 Windows 10 上,例如,如果在 Windows 控制面板中选择用户区域设置为 Cambodian:

enter image description here

但是如果用户在我的应用程序 UI 中选择 US English,我似乎无法找到一种方法来使用“US English numbers”来呈现它。在 Windows 8.1 上,无论选择何种区域设置,它过去看起来都是这样:

enter image description here

因为我的假设是不需要翻译数字。但在 Windows 10 上,相同的控件最终看起来是这样的:

enter image description here

请注意,它的文本仅使用此调用设置:

::SetWindowText(m_hWnd, L"1000");

所以我很好奇,有没有办法让数字呈现为阿拉伯数字:

enter image description here

最佳答案

这个问题比基本控件更深入,它发生在 GDI 内部,并且还会影响 DrawTextTextOut。唯一记录在案的方法是使用 ETO_NUMERICSLATIN 标志调用 ExtTextOut(或使用 Uniscribe 呈现文本)。

This behavior is completely by design

these flags only modify U+0030 -- U+0039, as needed

Becsause the truth is that GDI doesn't give a crap about formatting or really anything related to locales, with one signle exception: Digit Substitution

Any time you go to render text it will grab those digit substitution settings in the user locale (including the user override information) and use the info to decide how to display numbers.

另一件似乎有效的事情是强制使用 GREEK_CHARSET 字符集的自定义字体。该字符集触发 font association magic feature . (EE_CHARSET 似乎也适用于英文文本)。如果您要这样做,您可能必须尝试为每种语言选择最佳字符集,但您不能使用 ANSI_CHARSET 或 DEFAULT_CHARSET。

如果不知道为什么这只发生在 Windows 10 中,但在某些地方它确实看起来像是一个错误。例如,在资源管理器中,它将“7-Zip”显示为“៧-Zip”等。

关于c++ - 如何确保在 Windows 10 上将数字呈现为阿拉伯数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49582629/

相关文章:

serialization - 如何在没有外部库的任何lua中将 double 转换为小字符串表示而不会丢失数据?

c++ - 处理按钮表 (WinAPI)

javascript - 计算像 "loop "这样的数字

C++ : How can I know the size of Base class SubObject?

c++ - .cpp 和 .R 文件的常量

c++ - 如何在 Windows 7 64 位上设置 MinGw?

c++ - 读取标准输出文件

winapi - "GetForegroundWindow: identifier not found"在 Visual Studio 2015

multithreading - Delphi Win API CreateTimerQueueTimer 线程和线程安全 FormatDateTime 崩溃

java - 有没有更好的方法来检查字符串中是否有数字?