16,471
社区成员
发帖
与我相关
我的任务
分享
// remarksecretDlg.h : 头文件
//
#pragma once
#include "afxcmn.h"
#include <string>
// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLvnItemchangedList1(NMHDR *pNMHDR, LRESULT *pResult);
CListCtrl mlist; //自注:控件变量在这里设置
//wstring suffixStr;
afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedCheck1();
afx_msg void OnBnClickedCheck2();
afx_msg void OnBnClickedCheck3();
afx_msg void OnBnClickedCheck4();
afx_msg void OnBnClickedCheck5();
};
/ remarksecretDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "remarksecret.h"
#include "remarksecretDlg.h"
//#include "afxdialogex.h"
#include "Resource.h"
//#include "windows.h"
//#include <tchar.h>
#include <algorithm>
//#include <string>
#include <vector>
//#include <string>
//#include <iterator>
//#include <functional>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
using std::wstring;
wstring suffixStr;
struct FileInfo
{
std::wstring szFileName;
std::wstring szFilePath;
std::wstring szCreateTime;
};
BEGIN_MESSAGE_MAP(CremarksecretDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &CremarksecretDlg::OnLvnItemchangedList1)
ON_BN_CLICKED(IDC_BUTTON1, &CremarksecretDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_CHECK1, &CremarksecretDlg::OnBnClickedCheck1)
ON_BN_CLICKED(IDC_CHECK2, &CremarksecretDlg::OnBnClickedCheck2)
ON_BN_CLICKED(IDC_CHECK3, &CremarksecretDlg::OnBnClickedCheck3)
ON_BN_CLICKED(IDC_CHECK4, &CremarksecretDlg::OnBnClickedCheck4)
ON_BN_CLICKED(IDC_CHECK5, &CremarksecretDlg::OnBnClickedCheck5)
END_MESSAGE_MAP()
void CremarksecretDlg::OnBnClickedCheck1()
{
// TODO: 在此添加控件通知处理程序代码
//extern std::wstring suffixStr;
int nstatus=(((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck());
if(nstatus=1)
{
suffixStr==_T("doc")||suffixStr==_T("docx");
}
else
{
suffixStr==_T(" ");
}
}
void CremarksecretDlg::OnBnClickedCheck2()
{
// TODO: 在此添加控件通知处理程序代码
//extern std::wstring suffixStr;
int nstatus=(((CButton*)GetDlgItem(IDC_CHECK2))->GetCheck());
if(nstatus=1)
{
suffixStr==_T("pdf");
}
else
{
suffixStr==_T(" ");
}
}
void CremarksecretDlg::OnBnClickedCheck3()
{
// TODO: 在此添加控件通知处理程序代码
//extern std::wstring suffixStr;
int nstatus=(((CButton*)GetDlgItem(IDC_CHECK3))->GetCheck());
if(nstatus=1)
{
suffixStr==_T("ppt")||suffixStr==_T("pptx");
}
else
{
suffixStr==_T(" ");
}
}
void CremarksecretDlg::OnBnClickedCheck4()
{
// TODO: 在此添加控件通知处理程序代码
//extern std::wstring suffixStr;
int nstatus=(((CButton*)GetDlgItem(IDC_CHECK4))->GetCheck());
if(nstatus=1)
{
suffixStr==_T("xls")||suffixStr==_T("xlsx"); ;
}
else
{
suffixStr==_T(" ");
}
}
void CremarksecretDlg::OnBnClickedCheck5()
{
// TODO: 在此添加控件通知处理程序代码
//extern std::wstring suffixStr;
int nstatus=(((CButton*)GetDlgItem(IDC_CHECK5))->GetCheck());
if(nstatus=1)
{
suffixStr==_T("txt");
}
else
{
suffixStr==_T(" ");
}
}
//递归遍历所有文件
void find (LPCTSTR lpPath,std::vector<FileInfo>&FileList)
{
//std::vector<FileInfo>fileList;
std::wstring szFind(lpPath);
WIN32_FIND_DATA FindFileData;
szFind+=_T("\\*.*");
HANDLE hFind=::FindFirstFile(szFind.c_str(),&FindFileData);
if(INVALID_HANDLE_VALUE==hFind) return;
do//while(1)
{
if(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{//dir 目录在列表中可以双击打开,不要递归!
if(FindFileData.cFileName[0]!='.')
{
std::wstring szPath(lpPath);
szPath+=_T("\\");
szPath+=FindFileData.cFileName;
TRACE1("%s\n",szPath.c_str());
find(szPath.c_str(),FileList); //自注:这里小写的fileList不行。
}
}
else
{//file
std::wstring strFileName=FindFileData.cFileName;//文件名
/*std::wstring*/suffixStr=strFileName.substr(strFileName.find_last_of('.')+1);
void OnBnClickedCheck5();
if(suffixStr==_T("txt")) //根据后缀选出自己感兴趣的文件,比如txt文件,注意大小写,如果想不区分大小写,需要自己统一转化为大写或小写然后比较
{
FILETIME ft=FindFileData.ftCreationTime; //取得创建时间
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //转换成本地时间
FileTimeToSystemTime(&ft,&st); //在这句之前加上上一句,就不用再小时那里+8了。
swprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京时间*/,st.wMinute,st.wSecond);
std::wstring strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //文件全路径名
FileInfo fi; //自注:结构变量不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:这句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
//fi=FileList;
}
void OnBnClickedCheck1();
if(suffixStr==_T("doc")) //根据后缀选出自己感兴趣的文件,比如txt文件,注意大小写,如果想不区分大小写,需要自己统一转化为大写或小写然后比较
{
FILETIME ft=FindFileData.ftCreationTime; //取得创建时间
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //转换成本地时间
FileTimeToSystemTime(&ft,&st); //在这句之前加上上一句,就不用再小时那里+8了。
swprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);
std::wstring strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //文件全路径名
FileInfo fi;
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
FileList.push_back(fi);
}
else if(suffixStr==_T("docx")) //根据后缀选出自己感兴趣的文件,比如txt文件,注意大小写,如果想不区分大小写,需要自己统一转化为大写或小写然后比较
{
FILETIME ft=FindFileData.ftCreationTime; //取得创建时间
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //转换成本地时间
FileTimeToSystemTime(&ft,&st); //在这句之前加上上一句,就不用再小时那里+8了。
swprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);
std::wstring strFilePath=lpPath;
strFilePath+=FindFileData.cFileName; //文件全路径名
FileInfo fi;
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
FileList.push_back(fi);
}
void OnBnClickedCheck2();
}
}while(::FindNextFile(hFind,&FindFileData));
}
//FindClose(hFind);
#define BIF_NEWDIALOGSTYLE 0x0040
// CremarksecretDlg 消息处理程序
// TODO: 在此添加额外的初始化代码
mlist.SetExtendedStyle(mlist.GetExtendedStyle()|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
mlist.InsertColumn(0,_T("操作"),LVCFMT_LEFT,80);//100指定每列宽度
mlist.InsertColumn(1,_T("文件名"),LVCFMT_LEFT,500);
mlist.InsertColumn(2,_T("创建时间"),LVCFMT_LEFT,120);
mlist.InsertColumn(3,_T("路径"),LVCFMT_LEFT,360);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void CremarksecretDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码 自注:以下是我添加的代码
BROWSEINFO bi; //BROWSEINFO结构有很多成员参数可以自己设置
ZeroMemory(&bi,sizeof(BROWSEINFO)); //将以&bi为起始地址,大小为sizeof(BROWSEINFO)的内存区域用0填充
bi.ulFlags=BIF_BROWSEINCLUDEFILES; //设置弹出的对话框属性。此处意思为包含文件。如果不设这个值,默认的是只有文件夹。ulFlags还可以定义很多别的属性
bi.ulFlags=BIF_NEWDIALOGSTYLE; //窗口可以调整大小,有新建文件夹按钮
LPITEMIDLIST pidl = SHBrowseForFolder(&bi); //Displays a dialog box enabling the user to select a Shell folder.
TCHAR * path = new TCHAR[MAX_PATH]; //自注:点击按钮获得的地址在path变量中
if(pidl!= NULL)
{
SHGetPathFromIDList(pidl,path); //Converts an item identifier list to a file system path
//MessageBox(path);
}
//FileInfo fileList;
using std::vector;
vector<FileInfo>FileList; //自注:程序不承认FileList是个结构变量
//std::vector<FileInfo>fileList;
find(/*_T("D:\\xsmposc\\XSMPos"*/path,FileList); //取得文件信息,可自行插入列表框
//FileInfo fileList;
UINT nCount=FileList.size(); //得到控件的行数
//Filelist=fi;
int i;
CString empty;
CString name;
CString time;
CString mypath;
for(i=0;i<nCount;i++)
{
empty.Format(_T(""),i+1);
mlist.InsertItem(i,empty);
name.Format(_T("%s"),FileList[i].szFileName.c_str());
mlist.SetItemText(i,1,name); //插入列
time.Format(_T("%s"),FileList[i].szCreateTime.c_str());
mlist.SetItemText(i,2,time);
mypath.Format(_T("%s"),FileList[i].szFilePath.c_str());
mlist.SetItemText(i,3,mypath);
}
}
/////////////////////////////////////////////////////////////////////////////////////
string suffixStr;// UNICODE wstring
BOOL CShowdirDlg::GetTypes(string &str)
{
str="";// 1002 -> 1006
char tmp[10];
for (UINT n=IDC_CHECK1;n<=IDC_CHECK5; n++)
{
if(((CButton*)GetDlgItem(n))->GetCheck() == 1)
{
tmp[0]=0;
GetDlgItem(n)->GetWindowText(tmp,9);
str += tmp;
}
}
if(str.compare("")==0) return FALSE;
str += '.';// seperater
return TRUE;
}
void find(LPCTSTR lpPath,vector<FileInfo>& FileList)
{
string szFind(lpPath);
WIN32_FIND_DATA FindFileData;
szFind+=_T("\\*.*");
HANDLE hFind=::FindFirstFile(szFind.c_str(),&FindFileData);
if(INVALID_HANDLE_VALUE==hFind) return;
//
do
{
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{// dir
if(FindFileData.cFileName[0] != '.')
{
string szPath(lpPath);
szPath+=_T("\\");
szPath+=FindFileData.cFileName;
//TRACE1("%s\n",szPath.c_str());
find(szPath.c_str(),FileList);
}
}
else
{// file
string strFileName=FindFileData.cFileName;//文件名
//TRACE1("%s\n",strFileName.c_str());
int at = strFileName.find_last_of('.');
if(at<0) continue;// file without extention
string ext=strFileName.substr(at);
//TRACE1("%s\n",ext.c_str());
//
at=0;// reset
while(((int)at=suffixStr.find(ext,at))>=0)// find type
// if(stricmp(suffixStr.c_str(),_T(".txt"))==0)
{// not suffixStr.c_str()==_T(".txt") ; never == !
//afxDump << at << "\n";
at+=ext.size();// move to seperetor '.'
if(suffixStr[at]!='.') continue;// not wanted !
//
FILETIME ft=FindFileData.ftCreationTime;
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft);
FileTimeToSystemTime(&ft,&st);
sprintf(buf,_T("%4d年%02d月%02d日%02d:%02d:%02d"),
st.wYear,st.wMonth,st.wDay,st.wHour/*北京时间*/,st.wMinute,st.wSecond);
string strFilePath=lpPath;
FileInfo fi;
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
//TRACE1("%s\n",strFileName.c_str());
FileList.push_back(fi);
}
}
} while (::FindNextFile (hFind, &FindFileData));
}
#define BIF_NEWDIALOGSTYLE 0x0040
void CShowdirDlg::OnButton1()
{
// static LPITEMIDLIST s_pidl=0;
// new file types
if(!GetTypes(suffixStr))
{
AfxMessageBox("No file extention selected!");
return;
}
// afxDump << suffixStr.c_str() << "\n";
// get directory
BROWSEINFO bi;
ZeroMemory(&bi,sizeof(BROWSEINFO));
// bi.ulFlags=BIF_RETURNFSANCESTORS;
// bi.ulFlags=BIF_BROWSEINCLUDEFILES;
bi.ulFlags |= BIF_NEWDIALOGSTYLE;//窗口可以调整大小,有新建文件夹按钮
bi.lpszTitle="指定要处理的文件夹";
// if(s_pidl) bi.pidlRoot= s_pidl;
// Displays a dialog box enabling the user to select a Shell folder.
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
//
TCHAR * path = new TCHAR[MAX_PATH];
if(pidl != NULL)
{// Converts an item identifier list to a file system path
SHGetPathFromIDList(pidl,path);
}
else
{
return;
}
// if(pidl) s_pidl=pidl;
// window ruined by SHBrowseForFolder
m_list.DeleteAllItems();
RedrawWindow();
// get files info
CWaitCursor wait;
vector<FileInfo>fileList;
find(path,fileList);
// fill list
UINT nCount=fileList.size();
UINT i;
CString empty;
CString name;
CString time;
CString mypath;
m_list.LockWindowUpdate();
for(i=0;i<nCount;i++)
{
empty.Format("%d",i);
m_list.InsertItem(i,empty);
name.Format("%s",fileList[i].szFileName.c_str());
m_list.SetItemText(i,1,name);
time.Format("%s",fileList[i].szCreateTime.c_str());
m_list.SetItemText(i,2,time);
mypath.Format("%s",fileList[i].szFilePath.c_str());
m_list.SetItemText(i,3,mypath);
}
m_list.UnlockWindowUpdate();
}
void CremarksecretDlg::OnBnClickedCheck1()
{
// TODO: 在此添加控件通知处理程序代码
//extern std::wstring suffixStr;
int nstatus=(((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck());
if(nstatus=1)
{
suffixStr==_T("doc?") //||suffixStr==_T("docx");
}
else
{
suffixStr==_T(" ");
}
}
// showdirDlg.h : header file
//
#if !defined(AFX_SHOWDIRDLG_H__F25B36DD_2D3F_4037_A387_39BD82DE3D8F__INCLUDED_)
#define AFX_SHOWDIRDLG_H__F25B36DD_2D3F_4037_A387_39BD82DE3D8F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CShowdirDlg dialog
class CShowdirDlg : public CDialog
{
// Construction
public:
CShowdirDlg(CWnd* pParent = NULL); // standard constructor
BOOL GetTypes(string &str);
// Dialog Data
//{{AFX_DATA(CShowdirDlg)
enum { IDD = IDD_SHOWDIR_DIALOG };
CListCtrl m_list;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CShowdirDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CShowdirDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnButton1();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_SHOWDIRDLG_H__F25B36DD_2D3F_4037_A387_39BD82DE3D8F__INCLUDED_)
// showdirDlg.cpp : implementation file
//
#include "stdafx.h"
#include "showdir.h"
#include "showdirDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
typedef struct FileInfo
{
string szFileName;
string szFilePath;
string szCreateTime;
}FileInfo;
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShowdirDlg dialog
CShowdirDlg::CShowdirDlg(CWnd* pParent /*=NULL*/)
: CDialog(CShowdirDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CShowdirDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CShowdirDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CShowdirDlg)
DDX_Control(pDX, IDC_LIST1, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CShowdirDlg, CDialog)
//{{AFX_MSG_MAP(CShowdirDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShowdirDlg message handlers
BOOL CShowdirDlg::OnInitDialog()
{
// IDM_ABOUTBOX 必须在系统命令范围内。
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
char a[]="";//elloworld"; =00 CC CC CC ;
int n=sizeof("helloworld");//10+'0'
n=sizeof("");//1
n=sizeof("0");//2
n=sizeof("01");//3
n=sizeof("012");//4
// ShowWindow(SW_MINIMIZE);
m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
m_list.InsertColumn(0,_T(""),LVCFMT_LEFT,40);
m_list.InsertColumn(1,_T("文件名"),LVCFMT_LEFT,150);
m_list.InsertColumn(2,_T("创建时间"),LVCFMT_LEFT,200);
m_list.InsertColumn(3,_T("路径"),LVCFMT_LEFT,350);
return TRUE; // return TRUE unless you set the focus to a control
}
void CShowdirDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CShowdirDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CShowdirDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
/////////////////////////////////////////////////////////////////////////////////////
string suffixStr;// UNICODE wstring
BOOL CShowdirDlg::GetTypes(string &str)
{
str="";// 1002 -> 1006
char tmp[10];
for (UINT n=IDC_CHECK1;n<=IDC_CHECK5; n++)
{
if(((CButton*)GetDlgItem(n))->GetCheck() == 1)
{
tmp[0]=0;
GetDlgItem(n)->GetWindowText(tmp,9);
str += tmp;
}
}
if(str.c_str()=="") return FALSE;
str += '.';// seperater
return TRUE;
}
void find(LPCTSTR lpPath,vector<FileInfo>& FileList)
{
string szFind(lpPath);
WIN32_FIND_DATA FindFileData;
szFind+=_T("\\*.*");
HANDLE hFind=::FindFirstFile(szFind.c_str(),&FindFileData);
if(INVALID_HANDLE_VALUE==hFind) return;
do
{
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{// dir 目录 在 列表中 可以 双击 打开 ,不要 递归 !
if(FindFileData.cFileName[0] != '.')
{
string szPath(lpPath);
szPath+=_T("\\");
szPath+=FindFileData.cFileName;
//TRACE1("%s\n",szPath.c_str());
find(szPath.c_str(),FileList);
}
}
else
{// file
string strFileName=FindFileData.cFileName;//文件名
//TRACE1("%s\n",strFileName.c_str());
int at = strFileName.find_last_of('.');
if(at<0) continue;// file without extention
string ext=strFileName.substr(at);
TRACE1("%s\n",ext.c_str());
//
at=0;// reset
while(((int)at=suffixStr.find(ext,at))>=0)// find type
// if(stricmp(suffixStr.c_str(),_T(".txt"))==0)
{// not suffixStr.c_str()==_T(".txt") ; never == !
//afxDump << at << "\n";
at+=ext.size();// move to seperetor '.'
if(suffixStr[at]!='.') continue;// not wanted !
//
FILETIME ft=FindFileData.ftCreationTime; //取得创建时间
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //转换成本地时间
FileTimeToSystemTime(&ft,&st); //在这句之前加上上一句,就不用再小时那里+8了。
sprintf(buf,_T("%4d年%02d月%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京时间*/,st.wMinute,st.wSecond);
string strFilePath=lpPath;
//strFilePath+=_T("\\");
//strFilePath+=FindFileData.cFileName; //文件全路径名
FileInfo fi;
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
//TRACE1("%s\n",strFileName.c_str());
FileList.push_back(fi);
}
}
} while (::FindNextFile (hFind, &FindFileData));
}
#define BIF_NEWDIALOGSTYLE 0x0040
void CShowdirDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CWaitCursor wait;
//
BROWSEINFO bi; //BROWSEINFO结构有很多成员参数可以自己设置
ZeroMemory(&bi,sizeof(BROWSEINFO)); //将以&bi为起始地址,大小为sizeof(BROWSEINFO)的内存区域用0填充
bi.ulFlags=BIF_BROWSEINCLUDEFILES; //设置弹出的对话框属性。此处意思为包含文件。如果不设这个值,默认的是只有文件夹。ulFlags还可以定义很多别的属性
bi.ulFlags=BIF_NEWDIALOGSTYLE; //窗口可以调整大小,有新建文件夹按钮
bi.lpszTitle="指定要处理的文件夹"; //在窗口内显示提示用户的语句
LPITEMIDLIST pidl = SHBrowseForFolder(&bi); //Displays a dialog box enabling the user to select a Shell folder.
//
TCHAR * path = new TCHAR[MAX_PATH];
if(pidl != NULL)
{
SHGetPathFromIDList(pidl,path); //Converts an item identifier list to a file system path
}
// window ruined by SHBrowseForFolder
m_list.DeleteAllItems();
RedrawWindow();
// new file types
GetTypes(suffixStr);
// afxDump << suffixStr.c_str() << "\n";
vector<FileInfo>fileList;
find(path,fileList); //取得文件信息,可自行插入列表框
UINT nCount=fileList.size(); //得到控件的行数
UINT i;
CString empty;
CString name;
CString time;
CString mypath;
m_list.LockWindowUpdate();
for(i=0;i<nCount;i++)
{
empty.Format("%d",i);
m_list.InsertItem(i,empty);
name.Format("%s",fileList[i].szFileName.c_str());
m_list.SetItemText(i,1,name);
time.Format("%s",fileList[i].szCreateTime.c_str());
m_list.SetItemText(i,2,time);
mypath.Format("%s",fileList[i].szFilePath.c_str());
m_list.SetItemText(i,3,mypath);
}
m_list.UnlockWindowUpdate();
}
稍有改动, 因为 原来的 suffixStr.find 只 部分匹配,如 选 ‘.cpp’ 那么 "*.c" 也会 被选中。
#define BIF_NEWDIALOGSTYLE 0x0040
void CShowdirDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CWaitCursor wait;
BROWSEINFO bi; //BROWSEINFO结构有很多成员参数可以自己设置
ZeroMemory(&bi,sizeof(BROWSEINFO)); //将以&bi为起始地址,大小为sizeof(BROWSEINFO)的内存区域用0填充
bi.ulFlags=BIF_BROWSEINCLUDEFILES; //设置弹出的对话框属性。此处意思为包含文件。如果不设这个值,默认的是只有文件夹。ulFlags还可以定义很多别的属性
bi.ulFlags=BIF_NEWDIALOGSTYLE; //窗口可以调整大小,有新建文件夹按钮
bi.lpszTitle="指定要处理的文件夹"; //在窗口内显示提示用户的语句
LPITEMIDLIST pidl = SHBrowseForFolder(&bi); //Displays a dialog box enabling the user to select a Shell folder.
//
TCHAR * path = new TCHAR[MAX_PATH];
if(pidl != NULL)
{
SHGetPathFromIDList(pidl,path); //Converts an item identifier list to a file system path
}
//
GetTypes(suffixStr);
//
vector<FileInfo>fileList;
find(path,fileList); //取得文件信息,可自行插入列表框
UINT nCount=fileList.size(); //得到控件的行数
UINT i;
CString empty;
CString name;
CString time;
CString mypath;
m_list.LockWindowUpdate();
for(i=0;i<nCount;i++)
{
empty.Format("%d",i);
m_list.InsertItem(i,empty);
name.Format("%s",fileList[i].szFileName.c_str());
m_list.SetItemText(i,1,name);
time.Format("%s",fileList[i].szCreateTime.c_str());
m_list.SetItemText(i,2,time);
mypath.Format("%s",fileList[i].szFilePath.c_str());
m_list.SetItemText(i,3,mypath);
}
m_list.UnlockWindowUpdate();
}
给过你了 吧。