Windows Phone 8上的当前区域设置

时间:2013-08-12 21:07:47

标签: c++ winapi windows-phone-8 c++-cx

我正在寻找在C ++ / CX下的Windows Phone 8上获取设备区域设置的正确方法。

以下代码始终在Windows Phone 8模拟器上返回“en”

int ccBuf = GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT,
                            LOCALE_SISO639LANGNAME,
                            buf, 9);

1 个答案:

答案 0 :(得分:0)

此功能将以“en”,“fr”等两种字母格式返回设备的语言。

#include <windows.h>
std::string platformGetDeviceLanguage()
{
    ULONG numLanguages = 0;
    DWORD cchLanguagesBuffer = 0;
    BOOL hr = GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numLanguages, NULL, &cchLanguagesBuffer);

    if (hr) 
    {
        WCHAR* pwszLanguagesBuffer = new WCHAR[cchLanguagesBuffer];
        std::string lang_code = "en";
        hr = GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numLanguages, pwszLanguagesBuffer, &cchLanguagesBuffer);
        if (hr) 
        {
            lang_code[0] = pwszLanguagesBuffer[0];
            lang_code[1] = pwszLanguagesBuffer[1];
        }
        delete[] pwszLanguagesBuffer;
        return lang_code;
    }
    return "en";
}