字符集和代码页转换(charset-codepage)

字体相关用的都是字符集, 其他的语言判断方式都是用代码页
判断字体是否指定语言需要把字符集转换成代码页

字符集转换成代码页

	static	int		Charset2Codepage(DWORD dwCharset)
	{
		CHARSETINFO csInfo = {0}; 
		BOOL		bRetVal;

		bRetVal = TranslateCharsetInfo((DWORD *)dwCharset, &csInfo, TCI_SRCCHARSET);
		if(bRetVal == FALSE)
			return -1;

		return csInfo.ciACP;
	}

获取系统默认语言代码页

	static	int		GetDefCodepage(CHAR **ppName = NULL)
	{
		static		int		snCodepage = 0;
		static		CHAR	szCodepageName[MAX_PATH] = {};
		LANGID		Lgid;
		LCID		lcid;
		LCTYPE		nType;
		int			nRetVal, nCodePage;
		CPINFOEXA	cpInfo;

		if(snCodepage == 0)
		{
			Lgid = GetSystemDefaultLangID();
			lcid = Lgid;
			nCodePage = 0;
			nType = 1 ? LOCALE_IDEFAULTANSICODEPAGE : LOCALE_IDEFAULTCODEPAGE;
			nRetVal = GetLocaleInfoA(lcid, nType | LOCALE_RETURN_NUMBER, (CHAR *)&nCodePage, sizeof(nCodePage));
			if(nRetVal)
				snCodepage = nCodePage;
			nRetVal = GetCPInfoExA(nCodePage, 0, &cpInfo);
			if(nRetVal)
				strcpy(szCodepageName, cpInfo.CodePageName);
		}

		if(ppName)
			*ppName = szCodepageName;
		return snCodepage;
	}
posted @ 2025-02-22 14:57  Yofoo  阅读(16)  评论(0)    收藏  举报