新设想——VC开发多语言界面支持的新招
下面请跟着图老师小编一起来了解下新设想——VC开发多语言界面支持的新招,精心挑选的内容希望大家喜欢,不要忘记点个赞哦!
BOOL CLanguageManager::loadFromFile()
...{
BOOL bRead=FALSE;
int i;
ItemContext temp;
CStringArray itemBuf,valueBuf;
bRead = fileManager.GetSectionValues("Main Window",itemBuf,valueBuf);
if(bRead)
...{
for(i=0;i
...{
temp.UCtrlID = atoi(itemBuf.GetAt(i));
temp.strContext = valueBuf.GetAt(i);
m_vtContexts.push_back(temp);
}
}
itemBuf.RemoveAll();
valueBuf.RemoveAll();
bRead = fileManager.GetSectionValues("Login Dialog",itemBuf,valueBuf);
if(bRead)
...{
for(i=0;i
...{
temp.uCtrlID = atoi(itemBuf.GetAt(i));
temp.strContext = valueBuf.GetAt(i);
m_vtContexts.push_back(temp);
}
}
return bRead;
} 读取语言包配置信息: 以下是引用片段:
BOOL CIniFile::GetSectionValues(CString Section, CStringArray &strItemBuf, CStringArray &strValueBuf)
...{
BOOL bRead = FALSE;
ReadIniFile();//打开文件
if(bFileExist == FALSE FileContainer.GetSize() 0)
return bRead;//文件打开出错或文件为空,返回默认值
int i = 0;
int iFileLines = FileContainer.GetSize();
CString strline,str;
while(i
...{
strline = FileContainer.GetAt(i++);
strline.TrimLeft();
if(strline.GetLength()=0)
continue; //跳过空行
if(strline.Left(2)=="//")
continue; //跳过注释行
if(strline.GetAt(0)=='[')//查找Section,第一个必须为[
...{
str=strline.Left(strline.Find("]"));//去掉]右边
str=str.Right(str.GetLength()-str.Find("[")-1);//去掉[左边
str.TrimLeft();
str.TrimRight();
if(Section == str)//找到Section
...{
while(i
...{
strline = FileContainer.GetAt(i++);
strline.TrimLeft();
if(strline.GetLength()=0)
continue; //跳过空行
if(strline.GetAt(0)=='[')
return bRead;//假如到达下一个[],即找不到,返回默认值
if(strline.Left(2)=="//")
continue; //跳过注释行
str = strline.Left(strline.Find("="));//去掉=右边
str.TrimLeft();
str.TrimRight();
//保存等号左边项
strItemBuf.Add(str);
str=strline.Right(strline.GetLength()-strline.Find("=")-1);//去掉=左边
str.TrimLeft();
str.TrimRight();
//保存等号右边项
strValueBuf.Add(str);
bRead = TRUE;
}
//当前Section遍历结束
}
//没有找到Section
}
//当前行遍历结束
}
return bRead;
} 修改指定组件Caption属性代码:以下是引用片段:
BOOL CLanguageManager::setControlCaption(CWnd * pCtrl, UINT ctrlID)
...{
BOOL isOK=FALSE;
for(int i=0;i
...{
isOK = (m_vtContexts[i].uCtrlID==ctrlID);
if(isOK)
...{
pCtrl-SetWindowText(m_vtContexts[i].strContext);
break;
}
}
return isOK;
} 遍历设置指定窗口所有组件Caption属性代码: 以下是引用片段:
void CLanguageManager::setCaptionForWindow(CWnd * pWnd)
...{
//枚举对话框中所有组件
CWnd *pCtrl = pWnd-GetWindow(GW_CHILD);
while(pCtrl!=NULL)
...{
UINT ctrlID = pCtrl-GetDlgCtrlID();
setControlCaption(pCtrl,ctrlID);
pCtrl = pCtrl-GetNextWindow();
}
}