How can I detect Windows system language or codepage by Win32 or MFC ?
Is there some registry key to query ?
Thank you .
e.g.
WORD wDefLang = LANGIDFROMLCID(GetUserDefaultLCID());
LANGID wDefLang = GetSystemDefaultLangID(); // or
GetUserDefaultLangID();
There is some debate about which API is appropriate for your usage.
-- David
> How can I detect Windows system language or codepage by Win32 or MFC ?
It depends what you mean by "system language"
For each you have the option to get them in a numeric form
(LCID, used all the way to XP) or string (starting with Vista)
You can also get a language ID (LANGID), but it might not be enough
for all operations (a locale is usualy a better choice).
The language in which the UI was localized at install time?
GetSystemDefaultUILanguage -> LANGID
The language in which the UI is displayed right now?
(might be different than the system UI language if you have a MUI or LIP)
GetUserDefaultUILanguage -> LANGID
The system locale (that determines the ANSI and OEM code pages)?
GetSystemDefaultLocaleName -> string
GetSystemDefaultLCID -> LCID
GetSystemDefaultLangID -> LANGID
The locale used for locale-sensitive operations
(number/currency/date/time formatting, sorting, case conversion)?
GetUserDefaultLocaleName -> string
GetUserDefaultLCID -> LCID
GetUserDefaultLangID -> LANGID
For system code page there are two of them:
- the ANSI code page => GetACP
- the OEM code page, used (by default) by console apps => GetOEMCP
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
LCID lcid = ::GetThreadLocale() & 0x00ff;
lcid |= lcid == 0x0004?0x0800:0x0400; // Chinese starts with 08, but all
others 04
Then I build a filename for the language DLL using
CString csResourceDLL = GetResourceFilename(lcid, _T("MYAPP%1.dll"));
//
// Creates a resource file name (for a DLL) given the locale id and a format
string.
//
CString GetResourceFilename(UINT nLID, LPCTSTR cFormat)
{
CString csHex, cs;
csHex.Format(_T("%04x"), nLID);
cs.FormatMessage(cFormat,csHex);
return cs;
}
But we don't use the sub language since we don't support anything except a
few top level languages.
Tom
"Kid" <K...@discussions.microsoft.com> wrote in message
news:5E835E05-D8ED-4249...@microsoft.com...
> LCID lcid = ::GetThreadLocale() & 0x00ff;
What you need is LANGIDFROMLCID :-)
http://msdn.microsoft.com/en-us/library/dd318689%28v=VS.85%29.aspx
> lcid |= lcid == 0x0004?0x0800:0x0400; // Chinese starts with 08, but all
> others 04
...
> But we don't use the sub language since we don't support anything except a
> few top level languages.
Actually, you are trying to get the language.
For Chinese that is not enough, you have to look at the region.
That's because Chinese Traditional (usualy mapped to Chinese-Taiwan)
and Chinese Simplified (usualy mapped to Chinese-China) are not mutualy
inteligible.
It works just because you did not have to deal with other languages
that can be written with different scripts.
Examples:
- Azeri, Bosnian, Serbian, Uzbek (Cyrillic and Latin)
- Inuktitut (Latin and Inuktitut Syllabics)
- Mongolian (Cyrillic and Mongolian)
In fact, even the localizations for Portuguese Portugal and
Portuguese Brazil should be different, because they are kind of far,
even with if they use the same script.
Another problem is that language identifiers for
Bosnian, Croatian, and Serbian are numerically identical.
To differenciate between these languages you *must* look at the sublang.
@All :-)
Before answering, he should make sure he knows what he wants.
In the MS lingo, "Windows system language" is the one that determines the
ANSI/OEM code pages. It is not good to decide the UI language, or to format
stuff with it in a locale-sensitive manner.
It is different than the one from GetThreadLocale or GetUserDefaultLCID.