语言来显示对应的提示信息

根据当前软件设置的语言来显示对应的提示信息等

使用举例

int iKey = MULTILANGUAGESTART + 2063;
g_LanguageKey.Format("%d", iKey);
CString str = "The intersection cannot be set in a non idle state!";
str = g_SysLanguageInfo.GetCs("Prompted", g_LanguageKey, str);
if (AfxMessageBox(str, MB_RETRYCANCEL | MB_ICONWARNING) == IDCANCEL)
{
	return false;
}

SysLanguageInfo.h

// SysLanguageInfo.h: interface for the SysLanguageInfo class.
//
//

#if !defined(AFX_SysLanguageInfo_H__649ABA02_CEAE_4578_9107_B1483F42AA9F__INCLUDED_)
#define AFX_SysLanguageInfo_H__649ABA02_CEAE_4578_9107_B1483F42AA9F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define   MAX_BUFF   1024*3

class SysLanguageInfo
{
public:
	SysLanguageInfo();
	virtual ~SysLanguageInfo();
	
	
public:
	//		读系统配置信息
	void	ReadConfig(); 

	//		获取本程序的目录
	CString GetLocalDir(); 

	//		获取系统单位比例因子
	void	SetSysUnitScale(int nUnit);
	double  GetSysUnitScale(); 

	//		单位序号
	int		GetUnit(); //0 1, 2
	void	SetUnit(int nUnit);
	
	//		设置发行版本
	void	SetPublishVersion(int nType);
	
	//语言相关函数
public:
			//获取当前语言序号
	void	ReadLanguage(int iLanguageID); 

			//设置语言路径
	void	SetLanguagePath(); 
	
				//获取当前语言号
	int		GetCurrenLanguageID();
	/****************************************************************************
	*
	*参数:
	CDialog				*pDlg		对话框指针
	UINT				uDlgID		对话框ID
	*
	*返回值:
	*void
	*
	*描述:
	*设置 对话框控件 名称
	 当对话框运行时获取其所有可得到的字符串,并保存到语言文件中,每个控件用对话框ID和控件ID唯一标识
	****************************************************************************/
	void	SetDlgStrings(CDialog* pDlg, UINT uID, CString strSection);
			
	//		根据关键字获取配置文字
	CString GetCs(CString strKey);  //strSection== "String". strDefult = strKey
	CString GetCs(CString strSection,CString strKey,CString strDefault);

	CString GetToolItem(CString strSection,CString strKey,CString strDefault);
	
	//		config.ini字段读写
	CString LoadConfigString(CString strSect, CString strKey);
	void	SetConfigString(CString strSect, CString strKey, CString strText);
			
	//		指定语言
	BOOL	IsLanguage(int nLanguage);
	void	SetLanguage(int nLanguage);
	
	//		判断是否有指定语言项
	BOOL    EnableLanguage(int nLanguage);

	//		检测语言配置文件
	//void	CheckLanguageFile();

	//		设置语言组合
	void	SetLanguageGroup(int nLanguageGroup);
private:

public: 
	CString TrimValidString(CString strText); //去除回车换行字符

	
private: //私有成员变量
	int				m_nUnit;				// 系统单位序号 
	double			m_lfSysScale;			// 系统单位比例因子

	CString			m_strLocalDir;			// 程序目录
	CString			m_strConfig;			// 配置文件路径
	CString			m_strLanguagePath;		// 语言配置信息路径
	CString			m_strLangText;
	
	int				m_nLanguage;			// 当前语言序号
	int				m_nLanguageGroup;		// 当前配置的语言组合
	int				m_nPublish;				// 发行版本(0-单机,)	
};

#endif // !defined(AFX_SysLanguageInfo_H__649ABA02_CEAE_4578_9107_B1483F42AA9F__INCLUDED_)

SysLanguageInfo.cpp

// SysLanguageInfo.cpp: implementation of the SysLanguageInfo class.
//
//

#include "stdafx.h"
#include "SysLanguageInfo.h"
#include "direct.h"
#include "Symbol.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//
// Construction/Destruction
//

SysLanguageInfo::SysLanguageInfo()
{
	m_nUnit = 0;				// 系统单位序号 
	m_lfSysScale = 0.0;			// 系统单位比例因子

	//初始化本地目录
	m_strLocalDir = GetLocalDir();
	SetCurrentDirectory(m_strLocalDir);

}

SysLanguageInfo::~SysLanguageInfo()
{

}

struct LANGDEF
{
	UINT nID;
	char szLangName[256];
};

const LANGDEF languages[] =
{
	{ XTP_IDC_LANG_ARABIC,         "ArabicSa" },
	{ XTP_IDC_LANG_BULGARIAN,      "Bulgarian" },
	{ XTP_IDC_LANG_CHINESE_PRC,    "Chinese_Prc" },
	{ XTP_IDC_LANG_CHINESE_TAIWAN, "Chinese_Taiwan" },
	{ XTP_IDC_LANG_CROATIAN,       "Croatian" },
	{ XTP_IDC_LANG_CZECH,          "Czech" },
	{ XTP_IDC_LANG_DANISH,         "Danish" },
	{ XTP_IDC_LANG_DUTCH,          "Dutch" },
	{ XTP_IDC_LANG_ENGLISH,        "English" },
	{ XTP_IDC_LANG_ESTONIAN,       "Estonian" },
	{ XTP_IDC_LANG_FINNISH,        "Finnish" },
	{ XTP_IDC_LANG_FRENCH,         "French" },
	{ XTP_IDC_LANG_GERMAN,         "German" },
	{ XTP_IDC_LANG_GREEK,          "Greek" },
	{ XTP_IDC_LANG_HEBREW,         "Hebrew" },
	{ XTP_IDC_LANG_HUNGARIAN,      "Hungarian" },
	{ XTP_IDC_LANG_ITALIAN,        "Italian" },
	{ XTP_IDC_LANG_JAPANESE,       "Japanese" },
	{ XTP_IDC_LANG_KOREAN,         "Korean" },
	{ XTP_IDC_LANG_LATVIAN,        "Latvian" },
	{ XTP_IDC_LANG_LITHUANIAN,     "Lithuanian" },
	{ XTP_IDC_LANG_NORWEGIAN,      "Norwegian" },
	{ XTP_IDC_LANG_POLISH,         "Polish" },
	{ XTP_IDC_LANG_PORTUGUESE_BR,  "Portuguese_Br" },
	{ XTP_IDC_LANG_PORTUGUESE,     "Portuguese" },
	{ XTP_IDC_LANG_ROMANIAN,       "Romanian" },
	{ XTP_IDC_LANG_RUSSIAN,        "Russian" },
	{ XTP_IDC_LANG_SERBIAN,        "Serbian" },
	{ XTP_IDC_LANG_SLOVAK,         "Slovak" },
	{ XTP_IDC_LANG_SLOVENIAN,      "Slovenian" },
	{ XTP_IDC_LANG_SPANISH,        "Spanish" },
	{ XTP_IDC_LANG_SWEDISH,        "Swedish" },
	{ XTP_IDC_LANG_THAI,           "Thai" },
	{ XTP_IDC_LANG_TURKISH,        "Turkish" },
	{ XTP_IDC_LANG_UKRAINIAN,      "Ukrainian" },
};


void SysLanguageInfo::ReadConfig()
{
	m_nUnit = 0;
	SetSysUnitScale(m_nUnit);
	
	//初始化本地目录
	m_strLocalDir = GetLocalDir();
	SetCurrentDirectory(m_strLocalDir);
	
	
	//m_strWYPath.Format("\\Lang", m_strLocalDir);
	//  	if(!ec_load_unqlite(m_strWYPath + "\\kvite.dll"))
	//  		AfxMessageBox("Load database fauluer!!!");
	
	//m_strConfig.Format("%s\\Language\\IBrightCutConfig.ini", m_strLocalDir);
	
	//设定发行版本
	SetPublishVersion(PUBLISHVER_NORMAL); //PUBLISHVER_NORMAL--单机
	
	//设定有几种语言(0--简体,1--英文, 2--简体+英文, 3--繁体, 4--简体+英文+繁体,5)
// 	int nLanguageGroup = LANGUAGE_SIMPLIFIED|LANGUAGE_ENGLISH|LANGUAGE_COMPLICATED;
// 	SetLanguageGroup(nLanguageGroup);
	
	//m_strKvs.Format("%s\\InSystem.kvs", m_strLocalDir);
	//m_strUIni.Format("%s\\DlKsBx\\UserSysem.ini", m_strLocalDir);
	
	// 初始化语言
	//ReadLanguage();	
}

double SysLanguageInfo::GetSysUnitScale()
{
	
	return m_lfSysScale;
}

void SysLanguageInfo::SetSysUnitScale(int nUnit)
{
	switch (nUnit)
	{
	case UNIT_MM:
		{
			m_lfSysScale = UNIT_MM;
			break;
		}
	case UNITSCALE_CM:
		{
			m_lfSysScale = UNIT_CM;
			break;
		}
	case UNIT_INCH:
		{
			m_lfSysScale = UNIT_INCH;
			break;
		}
	default:
		{
			m_lfSysScale = UNIT_CM;
			break;
		}
	}
}

int SysLanguageInfo::GetUnit()
{
	return m_nUnit;
}

void SysLanguageInfo::SetUnit(int nUnit)
{
	m_nUnit = nUnit;
	SetSysUnitScale(nUnit);
}

void SysLanguageInfo::SetPublishVersion(int nType)
{
	m_nPublish = nType;
}

void SysLanguageInfo::SetLanguageGroup(int nLanguageGroup)
{
	m_nLanguageGroup = nLanguageGroup;
}
void SysLanguageInfo::ReadLanguage(int iLanguageID)
{
	char __cwd[256];
	getcwd(__cwd,256);
	
	
	

	if (iLanguageID > 0 )
	{
		m_nLanguage = iLanguageID;
	}
	else
	{
		m_nLanguage = XTP_IDC_LANG_ENGLISH;
	}
	
	SetLanguagePath();

	getcwd(__cwd,256);
	/
//	SetCurrentDirectory(__cwd);//by
}

// #define XTP_IDC_LANG_ARABIC             35200
// #define XTP_IDC_LANG_BULGARIAN          35201
// #define XTP_IDC_LANG_CHINESE_PRC        35202
// #define XTP_IDC_LANG_CHINESE_TAIWAN     35203
// #define XTP_IDC_LANG_CROATIAN           35204
// #define XTP_IDC_LANG_CZECH              35205
// #define XTP_IDC_LANG_DANISH             35206
// #define XTP_IDC_LANG_DUTCH              35207
// #define XTP_IDC_LANG_ENGLISH            35208
// #define XTP_IDC_LANG_ESTONIAN           35209
// #define XTP_IDC_LANG_FINNISH            35210
// #define XTP_IDC_LANG_FRENCH             35211
// #define XTP_IDC_LANG_GERMAN             35212
// #define XTP_IDC_LANG_GREEK              35213
// #define XTP_IDC_LANG_HEBREW             35214
// #define XTP_IDC_LANG_HUNGARIAN          35215
// #define XTP_IDC_LANG_ITALIAN            35216
// #define XTP_IDC_LANG_JAPANESE           35217
// #define XTP_IDC_LANG_KOREAN             35218
// #define XTP_IDC_LANG_LATVIAN            35219
// #define XTP_IDC_LANG_LITHUANIAN         35220
// #define XTP_IDC_LANG_NORWEGIAN          35221
// #define XTP_IDC_LANG_POLISH             35222
// #define XTP_IDC_LANG_PORTUGUESE         35223
// #define XTP_IDC_LANG_PORTUGUESE_BR      35224
// #define XTP_IDC_LANG_ROMANIAN           35225
// #define XTP_IDC_LANG_RUSSIAN            35226
// #define XTP_IDC_LANG_SERBIAN            35227
// #define XTP_IDC_LANG_SLOVAK             35228
// #define XTP_IDC_LANG_SLOVENIAN          35229
// #define XTP_IDC_LANG_SPANISH            35230
// #define XTP_IDC_LANG_SWEDISH            35231
// #define XTP_IDC_LANG_THAI               35232
// #define XTP_IDC_LANG_TURKISH            35233
// #define XTP_IDC_LANG_UKRAINIAN          35234

void SysLanguageInfo::SetLanguagePath()
{
    char __cwd[256];
	getcwd(__cwd,256);
	CString strLanguageId = "";
	CString strLangViewPath = "";

	for (int i = 0; i < _countof(languages); ++i)
	{
		if (m_nLanguage == languages[i].nID)
		{
			strLangViewPath.Format(_T("LangView\\%s.dll"), languages[i].szLangName);
			ec_load_language((LPSTR)(LPCTSTR)strLangViewPath);

	 		m_strLanguagePath.Format("%s\\Language\\IBrightCut%s.ini", m_strLocalDir, languages[i].szLangName);
		}
	}
	
	D_SetLanguage((LPSTR)(LPCTSTR)m_strLanguagePath);  //ly
}

int	SysLanguageInfo::GetCurrenLanguageID()
{
	return m_nLanguage;
}

BOOL SysLanguageInfo::EnableLanguage(int nLanguage)
{
	int nRet = (nLanguage&m_nLanguageGroup);
	return (nRet == nLanguage);
}

BOOL SysLanguageInfo::IsLanguage(int nLanguage)
{
	return (m_nLanguage == nLanguage);
}

void SysLanguageInfo::SetLanguage(int nLanguage)
{
	m_nLanguage = nLanguage;
}

void SysLanguageInfo::SetDlgStrings(CDialog *pDlg, UINT uDlgID, CString strSection)
{
	if (pDlg == NULL)
	{
		return;
	}

	CString strKey = "";
	CString strText = "";
	BOOL bTempFlag;
	

	BOOL bRead = TRUE; //1:从文件读,设置对话框 //0:从对话框读,保存到文件
	if(bRead)
	{
		CString strDefault = "";
		DWORD dwSize = 1000;
		char* pData = (char*)malloc(dwSize);

		//strSection.Format("IDD%d", uDlgID);

		//读对话框标题
		strKey.Format("IDD%d_Title", uDlgID);
		pDlg->GetWindowText(strText);
		if (!strKey.IsEmpty() && !strText.IsEmpty())
		{
			if(GetPrivateProfileString(strSection, strKey, "", pData, dwSize, m_strLanguagePath) != 0)
			{
				pDlg->SetWindowText(pData);
			}
			else
			{
				WritePrivateProfileString(strSection, strKey, strText, m_strLanguagePath);
			}
		}

		//写入各个子控件的标题文字
		CWnd* pWnd = pDlg->GetWindow(GW_CHILD);
		while(pWnd != NULL)
		{
			bTempFlag = TRUE;
			int iCtrlID = pWnd->GetDlgCtrlID(); 
			strKey.Format("IDD%d_%d", uDlgID, iCtrlID);
			pWnd->GetWindowText(strText);
			
	
			if (!strKey.IsEmpty() && !strText.IsEmpty())
			{
				CString Src;
				if(GetPrivateProfileString(strSection, strKey,"", pData,dwSize,m_strLanguagePath) != 0)
				{
					pWnd->SetWindowText(pData);
				}
				else
				{
					bool bNumFlag = true;
					bool bFloatFlag = false;
					for(int i = 0; i< strText.GetLength(); i++)
					{
						//strText.GetAt(i)>= 0x30 || strText.GetAt(i)<= 0x39 ||
						if (strText.GetAt(i) == 0x5c)
						{
							bTempFlag = FALSE;
						}							
					}
					
					CString Src = strText;
					if (Src ==  Src.SpanIncluding( _T("-0123456789.") ))
					{
						bTempFlag = FALSE;
					}
								
					if (bTempFlag)
					{
						switch(uDlgID)
						{
						case 243:
							{
								if ( iCtrlID < 1050 || iCtrlID >1057)
								{
									WritePrivateProfileString(strSection,strKey,strText,m_strLanguagePath);	
								}
								break;
							}
						default:
							{
								WritePrivateProfileString(strSection,strKey,strText,m_strLanguagePath);
								break;
							}
						}
						//bTempFlag = TRUE;
					}
				}
			}
			pWnd = pWnd->GetWindow(GW_HWNDNEXT);
		}

		//释放内存
		free(pData);
	}
// 	else //0:从对话框读,保存到文件
// 	{
// 		//写入对话框标题
// 		strKey.Format("IDD%d_Title", uDlgID);
// 		pDlg->GetWindowText(strText);
// 		WritePrivateProfileString(strSection, strKey, strText, m_strLanguagePath);
// 
// 		//写入各个子控件的标题文字
// 		CWnd* pWnd = pDlg->GetWindow(GW_CHILD);
// 		while(pWnd != NULL)
// 		{
// 			strKey.Format("IDD%d_%d", uDlgID, pWnd->GetDlgCtrlID());
// 			pWnd->GetWindowText(strText);
// 			WritePrivateProfileString(strSection, strKey, strText, m_strLanguagePath);
// 
// 			pWnd = pWnd->GetWindow(GW_HWNDNEXT);
// 		}
// 	}
}

CString SysLanguageInfo::GetCs(CString strKey)
{
	CString strValue = "";

	char buf[PCHLEN] = "";
	int nRet = GetPrivateProfileString("MenuBars", strKey, "", buf, PCHLEN, m_strLanguagePath);
	if (nRet <= 0)
	{
		WritePrivateProfileString("MenuBars", strKey, strKey, m_strLanguagePath);
		strValue = strKey;
	}
	else
	{
		strValue = buf;
	}
	
	return strValue;
}

CString SysLanguageInfo::GetCs(CString strSection, CString strKey, CString strDefault)
{
	CString strValue = "";
	char buf[PCHLEN] = "";

	int nRet = GetPrivateProfileString(strSection, strKey, "", buf, PCHLEN, m_strLanguagePath);
	if (nRet <= 0)
	{
		if ( !strDefault.IsEmpty() )
		{
			WritePrivateProfileString(strSection, strKey, strDefault, m_strLanguagePath);
			strValue = strDefault;
		}
		else
		{
			WritePrivateProfileString(strSection, strKey, strKey, m_strLanguagePath);
			strValue = strKey;
		}
		
	}
	else
	{
		strValue = buf;
	}
	
	return strValue;
}

CString SysLanguageInfo::GetToolItem(CString strSection,CString strKey,CString strDefault)
{
	CString strValue = "";
	char buf[PCHLEN] = "";
	CString	strFilePath = "";
	strFilePath = m_strLocalDir + "\\Language\\IBrightCutEnglish.ini";
	
	int nRet = GetPrivateProfileString(strSection, strKey, "", buf, PCHLEN, strFilePath);
	if (nRet > 0)
	{
		strValue = buf;
	}
	
	return strValue;
}

CString SysLanguageInfo::LoadConfigString(CString strSect, CString strKey)
{
	CString strValue = "";

	char buf[PCHLEN] = "";
	int nRet = GetPrivateProfileString(strSect, strKey, "", buf, PCHLEN, m_strConfig);
	if (nRet <= 0)
	{
		WritePrivateProfileString(strSect, strKey, strKey, m_strConfig);
		strValue = strKey;
	}	
	else
	{
		strValue = buf;
	}
	
	return strValue;
}

void SysLanguageInfo::SetConfigString(CString strSect, CString strKey, CString strText)
{
	WritePrivateProfileString(strSect, strKey, strText, m_strConfig);
}

CString SysLanguageInfo::GetLocalDir()
{
	int m = 0;
	char szBuf[PCHLEN] = "";
	CString strPath = "";//输出程序的路径
	
	::GetModuleFileName(NULL, szBuf, sizeof(szBuf));//得到本程序的目录
	
	strPath = szBuf;
	m = strPath.ReverseFind('\\');
	if (m != -1)
	{
		strPath = strPath.Left(m);
	}
	
	return strPath;
}

CString SysLanguageInfo::TrimValidString(CString strText)
{
	CString strInfo = strText;
	int nFind = strInfo.Find(_T('\n'));
	if (nFind >= 0)
	{
		if (nFind == 0)
		{
			strInfo = strText.Right(strInfo.GetLength()-1);
		}
		else
		{
			strInfo = strInfo.Left(nFind);
		}
	}

	return strInfo;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Minuw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值