标签:wstring play 文件夹 drop code pat eof text splay
1.选择目录
void CDecryptFileDlg::OnBnClickedSel()
{
std::wstring selectedDir;
WCHAR szDir[MAX_PATH];
ZeroMemory(szDir, sizeof(szDir));
BROWSEINFO bi;
bi.hwndOwner = m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szDir;
bi.lpszTitle = L"请选择目录:";
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
//选择目录
LPITEMIDLIST lp = SHBrowseForFolder(&bi);
if(lp && SHGetPathFromIDList(lp, szDir))
{
selectedDir = szDir;
selectedDir += L"\\";
}
SetDlgItemText(IDC_PATH, selectedDir.c_str());
}
2.拖拽文件
void CDecryptFileDlg::OnDropFiles(HDROP hDropInfo)
{
int DropCount = DragQueryFile(hDropInfo, -1, NULL, 0);
for(int i = 0; i < DropCount; i++)
{
WCHAR wcStr[MAX_PATH];
DragQueryFile(hDropInfo, i, wcStr, MAX_PATH);
//字符串拼接请自行处理
SetDlgItemText(IDC_PATH, wcStr);
}
DragFinish(hDropInfo);
}
3.遍历文件夹
void CDecryptFileDlg::BrowseCurrentAllFile(wstring strDir)
{
if(strDir.empty())
{
return;
}
else
{
if(strDir[strDir.length()-1] != L‘\\‘)
{
strDir += L"\\";
}
strDir = strDir + L"*.*";
}
CFileFind finder;
wstring strPath;
BOOL bWorking = finder.FindFile(strDir.c_str());
while(bWorking)
{
bWorking = finder.FindNextFile();
strPath = finder.GetFilePath();
if(finder.IsDirectory() && !finder.IsDots())
{
BrowseCurrentAllFile(strPath); //递归调用
}
else if(!finder.IsDirectory() && !finder.IsDots())
{
//strPaht就是所要获取的文件路径
DecryptFile(strPath);
}
}
}
标签:wstring play 文件夹 drop code pat eof text splay
原文地址:http://www.cnblogs.com/anow/p/7650371.html