📄 flefd.cpp
字号:
// FleFd.cpp : implementation file
//
#include "stdafx.h"
#include "FleFd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFleFd dialog
CFleFd::CFleFd(CWnd* pParent /*=NULL*/)
: CDialog(CFleFd::IDD, pParent)
{
//{{AFX_DATA_INIT(CFleFd)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CFleFd::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFleFd)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFleFd, CDialog)
//{{AFX_MSG_MAP(CFleFd)
ON_BN_CLICKED(IDC_dir_sel, Ondirsel)
ON_BN_CLICKED(IDC_SAVE_FILE, OnSaveFile)
ON_BN_CLICKED(IDC_start, Onstart)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFleFd message handlers
void CFleFd::Ondirsel()
{
// TODO: Add your control notification handler code here
LPBROWSEINFO lpbi=new BROWSEINFO;
lpbi->hwndOwner=GetSafeHwnd();
lpbi->pidlRoot=NULL;
lpbi->pszDisplayName=NULL;
lpbi->lpszTitle="请选择要遍历的目录位置:";
lpbi->ulFlags=BIF_RETURNONLYFSDIRS|BIF_STATUSTEXT;
lpbi->lpfn=NULL;
LPITEMIDLIST lpitemidlist=SHBrowseForFolder(lpbi);//显示文件对话框
if(lpitemidlist==NULL)
{
delete lpbi;
lpbi=NULL;
return;
}
char path[MAX_PATH];
SHGetPathFromIDList(lpitemidlist,path);//转换对象标志符列表为一个文件系统路径
delete lpbi;
CWnd* pWnd=(CWnd*)GetDlgItem(IDC_dir);//获取控件指针
pWnd->SetWindowText(path);//设置标题为当前路径信息
UpdateData(FALSE);// 更新对话框
}
void CFleFd::OnSaveFile()
{
// TODO: Add your control notification handler code here
CString strFilter;
strFilter="Txt Files(*.txt)|*.txt||";
CFileDialog dlg (FALSE,NULL,NULL,OFN_EXPLORER|OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_FILEMUSTEXIST,strFilter);
dlg.m_ofn.lStructSize=sizeof(OPENFILENAME);
if(dlg.DoModal()==IDOK)
{
strDirFile=dlg.GetPathName();
}
UpdateData(FALSE);
}
void CFleFd::Onstart()
{
// TODO: Add your control notification handler code here
CWnd* pWnd=(CWnd*)GetDlgItem(IDC_dir);
CString path,strHint;
pWnd->GetWindowText(path);
if(path.IsEmpty())
{
AfxMessageBox("目录不能位空");
return;
}
ExportFile.Open(strDirFile,CFile::modeCreate|CFile::modeWrite,NULL);
lfileCount=0;
ldirCount=0;
BrowseDir(path);
strHint.Format("共有文件夹%d文件%d个",ldirCount,lfileCount);
AfxMessageBox(strHint);
ExportFile.Close();
}
void CFleFd::BrowseDir(CString &strDir)
{
CFileFind cff;
CString szDir=strDir;
CString str;
if(szDir.Right(1)!="\\")
szDir+="\\";
szDir+="*.*";
BOOL bResult=cff.FindFile(szDir);
while(bResult)
{
bResult=cff.FindNextFile();
if(cff.IsDirectory()&&!cff.IsDots())
{
CString strPath=cff.GetFilePath();
BrowseDir(strPath);
ldirCount++;
}
else if(!cff.IsDirectory()&&!cff.IsDots())
{
CWnd* pWnd=(CWnd*)GetDlgItem(IDC_dir);
str.Format("%s",cff.GetFilePath());
pWnd->SetWindowText(str);
ExportFile.WriteString(str+"\n");
lfileCount++;
Sleep(10);
}
str="";
}
cff.Close();
}
BOOL CFleFd::OnInitDialog()
{
CDialog::OnInitDialog();
lfileCount=0;
ldirCount=0;
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -