VC++获取Windows操作系统的语言版本(附源码)

Posted dvlinker

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VC++获取Windows操作系统的语言版本(附源码)相关的知识,希望对你有一定的参考价值。

目录

1、系统提供的多个获取语言版本的API函数

2、各个函数在MSDN上的说明

3、获取操作系统语言的示例代码 

4、多国语言的语言id列表


        对于支持多语言版本的软件,是要运行在客户的Windows操作系统上的,是需要知道客户Windows操作系统的语言版本,比如简体中文操作系统、英文操作系统等。比如我们在制作支持多语言的安装包时,需要根据当前系统的语言,将启动安装时默认的语言设置为系统的语言,即如果当前使用的是简体中文操作系统,则默认使用中文简体,如果是英文操作系统,则要默认使用英文。本文就来讲述一下如何去获取Windows操作系统的语言版本。

1、系统提供的多个获取语言版本的API函数

   Windows系统提供了获取多个获取语言多个API函数:GetSystemDefaultLangIDGetUserDefaultLangIDGetSystemDefaultUILanguageGetUserDefaultUILanguage。这几个API函数很是类似和,到底该用哪一个呢?我们可以查看MSDN上这几个函数的说明,这几个还是有很大区别的,最终还是要使用GetUserDefaultUILanguage函数的。

2、各个函数在MSDN上的说明

       GetSystemDefaultLangID在MSDN上的说明:

Returns the language identifier for the system locale. This is the language used when displaying text in programs that do not support Unicode. It is set by the Administrator under Control Panel > Clock, Language, and Region> Administrative tab.  

由上述说明可知,GetSystemDefaultLangID函数获取的语言是控制面板 -> 区域与语言选项 -> 管理标签页中设置的支持的非Unicode语言,即如下图所示:

       GetUserDefaultLangID在MSDN上的说明:

Returns the language identifier for the current user as set under Control Panel > Clock, Language, and Region > Formats tab > Format dropdown.

由上述文字可知,GetUserDefaultLangID函数获取的语言是控制面板 -> 区域与语言选项 -> 格式标签页中设置的标准与格式语言,即如下图所示:

       GetSystemDefaultUILanguage在MSDN上的说明:

Retrieves the language identifier for the system default UI language of the operating system, also known as the "install language" on Windows Vista and later. For more information, see User Interface Language Management.

        GetUserDefaultUILanguage在MSDN上的说明:

Returns the language identifier for the user UI language for the current user. If the current user has not set a language, GetUserDefaultUILanguage returns the preferred language set for the system. If there is no preferred language set for the system, then the system default UI language (also known as "install language") is returned. For more information about the user UI language, see User Interface Language Management.

       综上所述,GetSystemDefaultLangID和GetUserDefaultLangID两函数获取的语言,受区域语言设置中设置的语言影响,所以这两个函数都不是我们想要的。我们需要获取的是Windows操作系统本身的语言版本。而GetSystemDefaultUILanguage的应用场景比较单一,使用GetUserDefaultUILanguage应该是最合适的。所以最终使用的是GetUserDefaultUILanguage函数。      

3、获取操作系统语言的示例代码 

       获取Windows操作系统语言版本的示例代码如下:

DWORD dwLangID = GetUserDefaultUILanguage(); 
if ( dwLangID == 0x0804 )

	// 简体中文

else if ( dwLangID == 0x0411 )

	// 日语

else 

	// 英语

在大家实际使用时,只要找到软件要支持的多语言中各个语种的id,添加相应的处理即可。  

4、多国语言的语言id列表

      可以到VC6对应的2001版本的msdn中,搜索GetSystemDefaultLangID函数(只有该函数的页面中有“Language Identifiers”的超链接),通过页面中的链接找到“Language Identifiers”点进去,在弹出的页面中,找到“Table of Language Identifiers”即可:

下面给出各个语种的语言列表:(下面将常见国家的语种标注出来了,比如简体中文、韩文、日文等)

IdentifierLanguage
0x0000Language Neutral
0x007fThe language for the invariant locale (LOCALE_INVARIANT). See MAKELCID.
0x0400Process or User Default Language
0x0800System Default Language
0x0436Afrikaans
0x041cAlbanian
0x0401Arabic (Saudi Arabia)
0x0801Arabic (Iraq)
0x0c01Arabic (Egypt)
0x1001Arabic (Libya)
0x1401Arabic (Algeria)
0x1801Arabic (Morocco)
0x1c01Arabic (Tunisia)
0x2001Arabic (Oman)
0x2401Arabic (Yemen)
0x2801Arabic (Syria)
0x2c01Arabic (Jordan)
0x3001Arabic (Lebanon)
0x3401Arabic (Kuwait)
0x3801Arabic (U.A.E.)
0x3c01Arabic (Bahrain)
0x4001Arabic (Qatar)
0x042bWindows 2000/XP: Armenian. This is Unicode only.
0x042cAzeri (Latin)
0x082cAzeri (Cyrillic)
0x042dBasque
0x0423Belarusian
0x0402Bulgarian
0x0455Burmese
0x0403Catalan
0x0404Chinese (Taiwan)
0x0804Chinese (PRC)
0x0c04Chinese (Hong Kong SAR, PRC)
0x1004Chinese (Singapore)
0x1404Windows 98/Me, Windows 2000/XP: Chinese (Macau SAR)
0x041aCroatian
0x0405Czech
0x0406Danish
0x0465Windows XP: Divehi. This is Unicode only.
0x0413Dutch (Netherlands)
0x0813Dutch (Belgium)
0x0409English (United States)
0x0809English (United Kingdom)
0x0c09English (Australian)
0x1009English (Canadian)
0x1409English (New Zealand)
0x1809English (Ireland)
0x1c09English (South Africa)
0x2009English (Jamaica)
0x2409English (Caribbean)
0x2809English (Belize)
0x2c09English (Trinidad)
0x3009Windows 98/Me, Windows 2000/XP: English (Zimbabwe)
0x3409Windows 98/Me, Windows 2000/XP: English (Philippines)
0x0425Estonian
0x0438Faeroese
0x0429Farsi
0x040bFinnish
0x040cFrench (Standard)
0x080cFrench (Belgian)
0x0c0cFrench (Canadian)
0x100cFrench (Switzerland)
0x140cFrench (Luxembourg)
0x180cWindows 98/Me, Windows 2000/XP: French (Monaco)
0x0456Windows XP: Galician
0x0437Windows 2000/XP: Georgian. This is Unicode only.
0x0407German (Standard)
0x0807German (Switzerland)
0x0c07German (Austria)
0x1007German (Luxembourg)
0x1407German (Liechtenstein)
0x0408Greek
0x0447Windows XP: Gujarati. This is Unicode only.
0x040dHebrew
0x0439Windows 2000/XP: Hindi. This is Unicode only.
0x040eHungarian
0x040fIcelandic
0x0421Indonesian
0x0410Italian (Standard)
0x0810Italian (Switzerland)
0x0411Japanese
0x044bWindows XP: Kannada. This is Unicode only.
0x0457Windows 2000/XP: Konkani. This is Unicode only.
0x0412Korean
0x0812Windows 95, Windows NT 4.0 only: Korean (Johab)
0x0440Windows XP: Kyrgyz.
0x0426Latvian
0x0427Lithuanian
0x0827Windows 98 only: Lithuanian (Classic)
0x042fFYRO Macedonian
0x043eMalay (Malaysian)
0x083eMalay (Brunei Darussalam)
0x044eWindows 2000/XP: Marathi. This is Unicode only.
0x0450Windows XP: Mongolian
0x0414Norwegian (Bokmal)
0x0814Norwegian (Nynorsk)
0x0415Polish
0x0416Portuguese (Brazil)
0x0816Portuguese (Portugal)
0x0446Windows XP: Punjabi. This is Unicode only.
0x0418Romanian
0x0419Russian
0x044fWindows 2000/XP: Sanskrit. This is Unicode only.
0x0c1aSerbian (Cyrillic)
0x081aSerbian (Latin)
0x041bSlovak
0x0424Slovenian
0x040aSpanish (Spain, Traditional Sort)
0x080aSpanish (Mexican)
0x0c0aSpanish (Spain, International Sort)
0x100aSpanish (Guatemala)
0x140aSpanish (Costa Rica)
0x180aSpanish (Panama)
0x1c0aSpanish (Dominican Republic)
0x200aSpanish (Venezuela)
0x240aSpanish (Colombia)
0x280aSpanish (Peru)
0x2c0aSpanish (Argentina)
0x300aSpanish (Ecuador)
0x340aSpanish (Chile)
0x380aSpanish (Uruguay)
0x3c0aSpanish (Paraguay)
0x400aSpanish (Bolivia)
0x440aSpanish (El Salvador)
0x480aSpanish (Honduras)
0x4c0aSpanish (Nicaragua)
0x500aSpanish (Puerto Rico)
0x0430Sutu
0x0441Swahili (Kenya)
0x041dSwedish
0x081dSwedish (Finland)
0x045aWindows XP: Syriac. This is Unicode only.
0x0449Windows 2000/XP: Tamil. This is Unicode only.
0x0444Tatar (Tatarstan)
0x044aWindows XP: Telugu. This is Unicode only.
0x041eThai
0x041fTurkish
0x0422Ukrainian
0x0420Windows 98/Me, Windows 2000/XP: Urdu (Pakistan)
0x0820Urdu (India)
0x0443Uzbek (Latin)
0x0843Uzbek (Cyrillic)
0x042aWindows 98/Me, Windows NT 4.0 and later: Vietnamese

以上是关于VC++获取Windows操作系统的语言版本(附源码)的主要内容,如果未能解决你的问题,请参考以下文章

vc实现多语言资源

C语言(VC++6.0)获取cpu编码

VC++ 获取文件名?求高手解答

在Windows系统中使用VC9VC11编译32位64位PHP及其扩展

php版本选择问题.VC6和VC9的区别,TS和NTS如何选择

VC++学习-创建C++文件以及输出HelloWorld