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 //
C#,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

相关文章