在 C++ 中以编程方式更改 Windows 语言设置
Change Windows language settings programmatically in C++
我尝试使用以下方法将语言从普通话设置为英语:
- SystemParametersInfoA
API returns 是的,但是从设备管理器收集数据的语言没有改变。
DWORD hKLEnglUS = 0x00000409;
if (SystemParametersInfoA(SPI_SETDEFAULTINPUTLANG, 0, &hKLEnglUS, SPIF_SENDCHANGE))
printf("Success!!\n");
else
printf("Error!!\n");
- SetLocaleInfoA
通过查看 GetLastError() 总是出现 1004 标志错误
LCID Locale = 0x409; //English - United States
if (SetLocaleInfoA(Locale, LOCALE_ILANGUAGE, "0x409"))
printf("Locale changed!\n");
else {
TCHAR m[] = _T("SetLocaleInfo");
ErrorExit(m);
}
“包含 C 源代码前缀的表示 LCID 数值的十六进制数字的 ASCII 字符串”是一种 确实 不寻常的格式。而且这不是正确的。
Language identifier with a hexadecimal value. For example, English (United States) has the value 0409, which indicates 0x0409 hexadecimal, and is equivalent to 1033 decimal. The maximum number of characters allowed for this string is five, including a terminating null character.
所以你需要传递 "0409"
没有 0x
前缀。
还有一条警告告诉您不要将 LOCALE_ILANGUAGE
与 SetLocaleInfo
一起使用。
Windows Vista and later: Use of this constant can cause GetLocaleInfo to return an invalid locale identifier. Your application should use the LOCALE_SNAME
constant when calling this function.
LOCALE_SNAME
的正确参数应该是 "en-US"
如 here
使用 SetThreadUILanguage 解决API
我尝试使用以下方法将语言从普通话设置为英语:
- SystemParametersInfoA
API returns 是的,但是从设备管理器收集数据的语言没有改变。
DWORD hKLEnglUS = 0x00000409;
if (SystemParametersInfoA(SPI_SETDEFAULTINPUTLANG, 0, &hKLEnglUS, SPIF_SENDCHANGE))
printf("Success!!\n");
else
printf("Error!!\n");
- SetLocaleInfoA
通过查看 GetLastError() 总是出现 1004 标志错误
LCID Locale = 0x409; //English - United States
if (SetLocaleInfoA(Locale, LOCALE_ILANGUAGE, "0x409"))
printf("Locale changed!\n");
else {
TCHAR m[] = _T("SetLocaleInfo");
ErrorExit(m);
}
“包含 C 源代码前缀的表示 LCID 数值的十六进制数字的 ASCII 字符串”是一种 确实 不寻常的格式。而且这不是正确的。
Language identifier with a hexadecimal value. For example, English (United States) has the value 0409, which indicates 0x0409 hexadecimal, and is equivalent to 1033 decimal. The maximum number of characters allowed for this string is five, including a terminating null character.
所以你需要传递 "0409"
没有 0x
前缀。
还有一条警告告诉您不要将 LOCALE_ILANGUAGE
与 SetLocaleInfo
一起使用。
Windows Vista and later: Use of this constant can cause GetLocaleInfo to return an invalid locale identifier. Your application should use the
LOCALE_SNAME
constant when calling this function.
LOCALE_SNAME
的正确参数应该是 "en-US"
如 here
使用 SetThreadUILanguage 解决API