C# 获取Windows语言类型(两种方式)
1 //Windows XP 简体中文测试的结果,涂聚文注.
2
3 using System.Runtime.InteropServices;//第一种API方式
4
5
6 //API方式:
7 [DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLangID")]
8 public static extern int GetSystemDefaultLangID();
9
10 [DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")]
11 public static extern int GetSystemDefaultLCID();
12
13 [DllImport("kernel32.dll", EntryPoint = "GetOEMCP")]
14 public static extern int GetOEMCP();
15
16 int lc = GetSystemDefaultLCID();
17 Response.Write(lc.ToString() + "<br>");//2052
18 int oem = GetOEMCP();
19 Response.Write(oem.ToString() + "<br>");//936
20 int languageint = GetSystemDefaultLangID();
21 Response.Write(languageint.ToString());//14682116
22
23 //
24 using System.Globalization;//第二种
25 Response.Write("<br/>操作系统:");
26 Response.Write(System.Globalization.CultureInfo.InstalledUICulture.NativeName.ToString() + "<br>");//操作系统:中文(中华人民共和国)
27 Response.Write(System.Globalization.CultureInfo.InstalledUICulture.LCID.ToString() + "<br>");//2052
28 Response.Write(System.Globalization.CultureInfo.InstalledUICulture.ThreeLetterWindowsLanguageName.ToString() + "<br>");//CHS
29 Response.Write(System.Globalization.CultureInfo.InstalledUICulture.ThreeLetterISOLanguageName.ToString() + "<br>");//zho
30 Response.Write(System.Environment.OSVersion.ToString() + "<br>"); //Microsoft Windows NT 5.1.2600 Service Pack 3
2
3 using System.Runtime.InteropServices;//第一种API方式
4
5
6 //API方式:
7 [DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLangID")]
8 public static extern int GetSystemDefaultLangID();
9
10 [DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")]
11 public static extern int GetSystemDefaultLCID();
12
13 [DllImport("kernel32.dll", EntryPoint = "GetOEMCP")]
14 public static extern int GetOEMCP();
15
16 int lc = GetSystemDefaultLCID();
17 Response.Write(lc.ToString() + "<br>");//2052
18 int oem = GetOEMCP();
19 Response.Write(oem.ToString() + "<br>");//936
20 int languageint = GetSystemDefaultLangID();
21 Response.Write(languageint.ToString());//14682116
22
23 //
24 using System.Globalization;//第二种
25 Response.Write("<br/>操作系统:");
26 Response.Write(System.Globalization.CultureInfo.InstalledUICulture.NativeName.ToString() + "<br>");//操作系统:中文(中华人民共和国)
27 Response.Write(System.Globalization.CultureInfo.InstalledUICulture.LCID.ToString() + "<br>");//2052
28 Response.Write(System.Globalization.CultureInfo.InstalledUICulture.ThreeLetterWindowsLanguageName.ToString() + "<br>");//CHS
29 Response.Write(System.Globalization.CultureInfo.InstalledUICulture.ThreeLetterISOLanguageName.ToString() + "<br>");//zho
30 Response.Write(System.Environment.OSVersion.ToString() + "<br>"); //Microsoft Windows NT 5.1.2600 Service Pack 3
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)