实现多国语言的几个小知识
获取模块(exe,dll)的执行目录
CString szCurPath(""), szModelPath;
GetModuleFileName(NULL,szCurPath.GetBuffer(MAX_PATH),MAX_PATH);
szCurPath.ReleaseBuffer();
szModelPath = szCurPath.Left(szCurPath.ReverseFind('//') + 1); //去掉模块的名字
寻找目录下的文件
CFileFind find;
//Call this member function to open a file search
bool bRet = find.FindFile(szCurPath + "*.txt");
CString szEng = "";
while(bRet)
{
bRet = find.FindNextFile();
if(find.IsDots() || find.IsDirectory()) continue;
CString szFileName = find.GetFileName();
//....
}
find.Close();
创建一个目录
CreateDirectory(szPath,NULL);
把资源文件中的某一项写出为文件
HRSRC hSrc = FindResource(NULL,MAKEINTRESOURCE(nID),_T("OWNER_DATA"));
if(hSrc == NULL) return false;
HGLOBAL hGlobal = LoadResource(NULL,hSrc);
if(hGlobal == NULL) return false;
LPVOID lp = LockResource(hGlobal);
DWORD dwSize = SizeofResource(NULL,hSrc);
CFile file;
if(file.Open(szPathName,CFile::modeCreate|CFile::modeWrite))
{
file.Write(lp,dwSize);
file.Close();
}
FreeResource(hGlobal);
配置文件的读写
字符串:
GetPrivateProfileString
WritePrivateProfileString
遍历对话框的子控件
CWnd* pWnd = pDlg->GetWindow(GW_CHILD);
while(pWnd != NULL)
{
//******
//pWnd->GetDlgCtrlID()
pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}
获得菜单
CWnd::GetMenu()
遍历菜单:
CMenu的几个成员函数:
GetSubMenu
GetMenuItemCount
GetMenuItemID
参考:
程序实现多国语言的动态切换解决方案
作者:耿海增