// Language.cpp: implementation of the CLanguage class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "DataManager.h" #include "Language.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif CLanguage CLanguage::m_self; ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CLanguage::CLanguage() { m_mapWords.SetAt("Upper Alarm", "过高报警"); m_mapWords.SetAt("Normal", "恢复正常"); m_mapWords.SetAt("Low Alarm", "过低报警"); m_hDll = NULL; m_pfTranslate = NULL; m_pfInit = NULL; } CLanguage::~CLanguage() { FreeDll(); } CString CLanguage::GetCurLanguage(CString strOrigTxt) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strRtn = strOrigTxt; if(m_self.m_pfTranslate) { int nSize = 1024; char* pBuf = new char[nSize]; try { int nSizeT = m_self.m_pfTranslate(strOrigTxt, pBuf, nSize-1); if(nSizeT >= nSize) { delete []pBuf; nSize = nSizeT + 1; pBuf = new char[nSize]; nSizeT = m_self.m_pfTranslate(strOrigTxt, pBuf, nSize-1); } } catch (...) { } strRtn = pBuf; delete []pBuf; } return strRtn; } int CLanguage::ShowMessageBox(LPCTSTR lpszText, UINT nType /* = MB_OK */, UINT nIDHelp /* = 0 */) { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); return AfxMessageBox(GetCurLanguage(lpszText), nType, nIDHelp); } UINT MessageBoxProc(LPVOID lParam) { CString *pstr = (CString*)lParam; AfxMessageBox(*pstr); delete pstr; return 23; } int CLanguage::ShowMessageBoxEx(LPCTSTR lpszText, UINT nType /* = MB_OK */, UINT nIDHelp /* = 0 */) { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString *pstr = new CString(GetCurLanguage(lpszText)); AfxBeginThread(MessageBoxProc, pstr); return MB_OK; } int CLanguage::ShowMessageBox(UINT nIDPrompt, UINT nType, UINT nIDHelp) { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); return AfxMessageBox(nIDPrompt, nType, nIDHelp); } BOOL CLanguage::LoadDll() { if(m_self.m_hDll == NULL) { m_self.m_hDll = LoadLibrary("TransInterface.dll"); if(m_self.m_hDll) { m_self.m_pfTranslate = (Def_Translate*)GetProcAddress(m_self.m_hDll, "Translate"); m_self.m_pfInit = (Def_Init*)GetProcAddress(m_self.m_hDll, "Init"); m_self.m_pfFree = (Def_Free*)GetProcAddress(m_self.m_hDll, "Free"); } else { } } return (m_self.m_hDll != NULL); } void CLanguage::FreeDll() { if(m_self.m_hDll) { FreeLibrary(m_self.m_hDll); m_self.m_hDll = NULL; m_self.m_pfInit = NULL; m_self.m_pfFree = NULL; } } void CLanguage::InitLanguage(HWND hWnd) { if(m_self.m_pfInit) { try { m_self.m_pfInit(hWnd); } catch (...) { } } } void CLanguage::FreeLanguage() { if(m_self.m_pfFree) { try { m_self.m_pfFree(); } catch (...) { } } }