strCaption = fileManager.GetString(section,"IDC_Stc_ListStudent",""); SetDlgItemText(IDC_Stc_ListStudent,strCaption); strCaption = fileManager.GetString(section,"IDC_Stc_AllContent",""); SetDlgItemText(IDC_Stc_AllContent,strCaption); |
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<itemBuf.GetSize();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<itemBuf.GetSize();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<iFileLines) ...{ 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<iFileLines) ...{ 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; } |
BOOL CLanguageManager::setControlCaption(CWnd * pCtrl, UINT ctrlID) ...{ BOOL isOK=FALSE; for(int i=0;i<m_vtContexts.size();i++) ...{ isOK = (m_vtContexts[i].uCtrlID==ctrlID); if(isOK) ... } return isOK; } |
void CLanguageManager::setCaptionForWindow(CWnd * pWnd) ...{ //枚举对话框中所有组件 CWnd *pCtrl = pWnd->GetWindow(GW_CHILD); while(pCtrl!=NULL) ...{ UINT ctrlID = pCtrl->GetDlgCtrlID(); setControlCaption(pCtrl,ctrlID); pCtrl = pCtrl->GetNextWindow(); } } |
评论