欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

获取“区域““国家或地区““语言“信息

程序员文章站 2022-05-09 14:06:37
...

获取"区域"“国家或地区”"语言"信息

获取“区域““国家或地区““语言“信息

获取"国家或地区"信息Code win C++

include <Windows.h>
PFUSSCOMMON_API BOOL CmnIsBlackIx1400()
{
	LANGID LangLCID = 0;
	TCHAR GeoData[MAX_PATH] = { 0 };
	GEOID GeoId = 0;

	LangLCID = GetUserDefaultLCID();
	GeoId = GetUserGeoID(GEOCLASS_NATION);
	
	if (!GetGeoInfo(GeoId, GEO_ISO2, GeoData, MAX_PATH, LangLCID))
		return FALSE;

	g_clsLog.WriteLog(theApp.m_bLogMode, theApp.m_szLogPath, __FILE__, __LINE__, _T("INFO"), _T("GeoData:%s"), GeoId);

	if (memcmp(GeoData,"US",2) == 0			//米国			U.S.
		|| memcmp(GeoData, "CL", 2) == 0	//チリ			Chile
		|| memcmp(GeoData, "CA", 2) == 0	//カナダ		Canada
		|| memcmp(GeoData, "PE", 2) == 0	//ペルー		Peru
		|| memcmp(GeoData, "MX", 2) == 0	//メキシコ		Mexico
		|| memcmp(GeoData, "CO", 2) == 0	//コロンビア	Columbia
		|| memcmp(GeoData, "AR", 2) == 0	//アルゼンチン	Argentina
		){
		return TRUE;
	}
	return FALSE;
}

Code win C#

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

namespace ConsoleApplication2
{
    class Program
    {
        private enum SYSGEOCLASS
        {
            GEOCLASS_NATION = 16,
            GEOCLASS_REGION = 14,
            GEOCLASS_ALL = 0
        };

        private enum SYSGEOTYPE
        {
            GEO_NATION = 0x0001,
            GEO_LATITUDE = 0x0002,
            GEO_LONGITUDE = 0x0003,
            GEO_ISO2 = 0x0004,
            GEO_ISO3 = 0x0005,
            GEO_RFC1766 = 0x0006,
            GEO_LCID = 0x0007,
            GEO_FRIENDLYNAME = 0x0008,
            GEO_OFFICIALNAME = 0x0009,
            GEO_TIMEZONES = 0x000A,
            GEO_OFFICIALLANGUAGES = 0x000B,
            GEO_ISO_UN_NUMBER = 0x000C,
            GEO_PARENT = 0x000D
        };

        [DllImport("Kernel32.dll", EntryPoint = "GetUserDefaultLCID")]
        private static extern ushort GetUserDefaultLCID();

        [DllImport("Kernel32.dll", EntryPoint = "GetUserGeoID")]
        private static extern Int32 GetUserGeoID(SYSGEOCLASS GeoClass);

        [DllImport("Kernel32.dll", CharSet = CharSet.Auto, EntryPoint = "GetGeoInfo", CallingConvention = CallingConvention.Cdecl)]
        private static extern int GetGeoInfo(Int32 Location, SYSGEOTYPE GeoType, StringBuilder lpGeoData, int cchData, ushort LangId);

        public static bool IsBlackIx1400()
        {
            ushort LangLCID = GetUserDefaultLCID();
            Int32 GeoId = GetUserGeoID(SYSGEOCLASS.GEOCLASS_NATION);
            StringBuilder GeoData = new StringBuilder(32);

            if (GetGeoInfo(GeoId, SYSGEOTYPE.GEO_ISO2, GeoData, 32, LangLCID) == 0)
            {
                return false;
            }
            string sGeoData = GeoData.ToString();
            if (sGeoData.Equals("US")         //米国			U.S.
                || sGeoData.Equals("CL")      //チリ			Chile
                || sGeoData.Equals("CA")      //カナダ		    Canada
                || sGeoData.Equals("PE")      //ペルー		    Peru
                || sGeoData.Equals("MX")      //メキシコ		Mexico
                || sGeoData.Equals("CO")      //コロンビア	    Columbia
                || sGeoData.Equals("AR")      //アルゼンチン	Argentina
                )
            {
                return true;
            }

            return false;
        }

        static void Main(string[] args)
        {
            bool black_iX1400 = Program.IsBlackIx1400();
            Console.WriteLine(black_iX1400);
        }
    }
}

查询"国家或地区"使用函数GetUserGeoID();
查询"区域格式"使用函数GetUserDefaultLCID()或GetUserDefaultLangID()判断返回值即可;
查询"系统语言"使用函数GetSystemDefaultLangID()判断返回值。