|
[free]//====================================
// 函数名称 : GetDirFiles
// 函数介绍 : 取得某目录下所有指定属性的文件名
// 返 回 值 : 选择的文件夹全路径
//
//====================================
bool CAppUtility::GetDirFiles( LPCTSTR lpDir,//目录 std::vector<CAppUtility::_FileStru_>&arr,// 返回文件
LPCTSTR lpExt/*="*.*"*/,// 寻找的文件类型
bool bIsIncludeSub/* = true*/// 是否包含子目录)
{
CString szPath = lpDir;
if ( szPath.IsEmpty() )
return false;
if ( szPath.Right(1) != _T('\\') )
szPath += _T("\\");
// 进入路径
if ( _tchdir(szPath) != 0 )
return false;
_FileStru_ aFile;
_tcscpy(aFile.szPath, szPath);// 路径
intptr_t hHand = _tfindfirst(lpExt, &aFile);
if ( -1 == hHand )
return false;
for (int nRet=0; nRet!=-1; nRet=_tfindnext(hHand, &aFile))
{
// 判断如果是.或..则继续循环
if ( 0 == _tcscmp(aFile.name, _T(".")) ||
0 == _tcscmp(aFile.name, _T("..")) )
continue;
// 如果是目录,则进入
if ( aFile.IsDir() )
{
if ( !bIsIncludeSub )
continue;
CString szSub = szPath + aFile.name+_T("\\");
GetDirFiles(szSub, arr, lpExt, bIsIncludeSub);
}
else
{
_stprintf(aFile.szPath, _T("%s%s"), szPath, aFile.name);
// 分解文件名与后缀
CString strTemp(aFile.name);
// 从后向前分离出文件名、格式名(以.为分界符)
int nPos = strTemp.ReverseFind(_T('.'));
if ( -1 != nPos )
{
_tcscpy(aFile.strExtOnly, strTemp.Mid(nPos+1,strTemp.GetLength()-nPos));
strTemp = strTemp.Mid(0,nPos);
}
else
aFile.strExtOnly[0] = _T('');
_tcscpy(aFile.strNameOnly, strTemp);
arr.push_back(aFile);
}
}
_findclose(hHand);
return true;
}
extern "C" __declspec(dllexport) int CALLBACK EnumFontFamProc(LPENUMLOGFONT lpelf,LPNEWTEXTMETRIC lpntm,DWORD nFontType,long lparam)
{
CComboBox *pComb = (CComboBox *) ((void*)lparam);
pComb->AddString(lpelf->elfLogFont.lfFaceName); //Style
return 1;
}
void InitFontCmb()
{
LOGFONT lf;
CClientDC dc (this);
lf.lfCharSet = ANSI_CHARSET; //中国标准字体
_tcscpy(lf.lfFaceName,_T("")); //设置Style
::EnumFontFamiliesEx((HDC) dc,&lf,(FONTENUMPROC)EnumFontFamProc,(LPARAM) (&m_cmbFont),0);
// 寻找字体
std::vector<CAppUtility::_FileStru_>arrSHX;
CAppUtility::GetDirFiles(CAppUtility::GetCADPath()+_T("Font"), arrSHX, _T("*.shx"), true);
CAppUtility::GetDirFiles(CAppUtility::GetPathFont(), arrSHX, _T("*.shx"), true);
for (int i=0; i<(int)arrSHX.size(); ++i)
{
if ( m_cmbFont.FindString(-1, arrSHX[i].strNameOnly) != -1 )
continue;
m_cmbFont.AddString(arrSHX[i].strNameOnly);
}
}[/free] |
|