How to get current operating system language?

2019-03-01 12:56发布

问题:

I am newbie to mfc, and I got struck over how to get the current operating system language (Ex: If it is English operating system I must get it as English and locale can be different. For English OS locale can be Japanese vice versa).

Current locale I am getting it through GetSystemDefaultLangID and the only thing I was left with is I need to get the current operating system language.

Can anyone kindly help me to resolve this issue.

回答1:

This came up before. Maybe you need GetUserDefaultUILanguage?

User Interface Language Management

int wmain(int argc, _TCHAR* argv[])
{
    wcout << "GetUserDefaultUILanguage:   " << GetUserDefaultUILanguage() << endl;
    wcout << "GetSystemDefaultUILanguage: " << GetSystemDefaultUILanguage() << endl;
    wcout << endl;
    wcout << "GetUserDefaultLangID:       " << GetUserDefaultLangID() << endl;
    wcout << "GetSystemDefaultLangID:     " << GetSystemDefaultLangID() << endl;
    wcout << endl;
    wcout << "GetUserDefaultLCID:         " << GetUserDefaultLCID() << endl;
    wcout << "GetSystemDefaultLCID:       " << GetSystemDefaultLCID() << endl;
    wcout << endl;

    wchar_t buf[100];
    LCID lcid = GetUserDefaultLCID();
    cout << "GetUserDefaultLCID: " << endl;
    if (GetLocaleInfo(lcid, LOCALE_ILANGUAGE, buf, 100)) wcout << buf << endl;
    if (GetLocaleInfo(lcid, LOCALE_SENGLANGUAGE, buf, 100))  wcout << buf << endl;
    if (GetLocaleInfo(lcid, LOCALE_SISO639LANGNAME, buf, 100)) wcout << buf << endl << endl;

    system("pause");
    return 0;
}


标签: winapi mfc