如何获得Windows区域位置设置? [英] How do I get the windows regional location setting?

查看:33
本文介绍了如何获得Windows区域位置设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以找到很多有关如何在.Net中获取区域和文化设置的信息,但是这些信息都无法获取当前的LOCATION设置.除了使用新的Location API以外,还有谁知道该怎么做(它需要在> = XP上运行).

I can find lots of information on how to get the regional and cultural settings in .Net but none of these get the current LOCATION setting. Does anyone know how to do this other than using the new Location API (it needs to work on >= XP).

如果不确定,该位置将在位置"标签中的区域设置中设置,而不是在格式"或语言"标签中设置.

In case your unsure, the location is set in the regional settings in the LOCATION tab, not the Formats or Languages tabs.

谢谢

推荐答案

啊!终于找到了它: http://social.msdn.microsoft.com/Forums/zh-CN/netfxbcl/thread/a4bb7327-f9d3-4115-a455-f664a0818120

链接中的必需代码:

using System.Runtime.InteropServices;
using System.Text;

private const int GEOCLASS_NATION = 16;

//SYSGEOTYPE
private const int GEO_NATION = 1;
private const int GEO_LATITUDE = 2;
private const int GEO_LONGITUDE = 3;
private const int GEO_ISO2 = 4;
private const int GEO_ISO3 = 5;
private const int GEO_RFC1766 = 6;
private const int GEO_LCID = 7;
private const int GEO_FRIENDLYNAME = 8;
private const int GEO_OFFICIALNAME = 9;
private const int GEO_TIMEZONES = 10;
private const int GEO_OFFICIALLANGUAGES = 11;


[DllImport("kernel32.dll")]
static extern int GetUserGeoID(int geoId);
[DllImport("kernel32.dll")]
static extern int GetGeoInfo(int geoid, int GeoType, StringBuilder lpGeoData, int cchData, int langid);
[DllImport("kernel32.dll")]
static extern int GetUserDefaultLCID();

static void Main(string[] args)
{
  int geoId = GetUserGeoID(GEOCLASS_NATION);
  string friendlyName = GetGeoFriendlyName(geoId);
}


private string GetGeoFriendlyName(int geoId)
{
  int lcid = GetUserDefaultLCID();
  StringBuilder bldr = new StringBuilder(50);
  GetGeoInfo(geoId, GEO_FRIENDLYNAME, bldr, bldr.Capacity, lcid);

  return bldr.ToString();
}

这篇关于如何获得Windows区域位置设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆