什么方法可以得到一个文件夹里头的所有子文件?给点提示 或者把重要代码贴出来一下 3Q3Q
解决方案 »
- InitInstance和OnInitDialog有什么不同
- VC 2008 怎么生成在没装VC的机器上直接运行?
- 由CListCtrl派生
- 有知道的吗?我想在WORD里嵌入一个按钮,点击然后发送打印消息给WORD,不知道该如何实现?
- 哪位大侠能告一下关于模板类CList的用法?
- 急!急!急!我的工程在debug版本下运行正常,但在release下却宕掉
- Edit控件怎样将一行中的内容给一个CString对象??怎么总不行啊
- 麻烦各位推荐c++方面的好书(thinking in C++和c++primer)那本书更好
- 自画按钮的问题
- 剑走偏锋,一个生僻的问题——怎样在Windows2000的服务里取得读取注册表的权限??
- How to building a "hello world" in Microsoft Visual C++ 2005 Express Edition?
- 基于对话框的程序,我在XXXDlg.cpp中的全局函数需要访问XXXDlg.h中定义的变量,用几条什么语句?
2 给你一个TreeCtrl的例子.void CFileTreeDlg::AddFile(CString StrPath, HTREEITEM faItem )
//StrPath为传递过来的目录层次,本次函数调用中搜索的文件都是它的下一层的。
//faItem为传递过来的Tree节点,本次函数调用中添加的Tree节点都是它的子节点。
{
CFileFind OneFile;
CString FName, DirName;
BOOL BeWorking;
HTREEITEM NewItem; DirName = StrPath+"\\*.*";
BeWorking = OneFile.FindFile( DirName );
while ( BeWorking ) { //BeWorking非零,指找了文件或目录 //查找同级的目录
BeWorking = OneFile.FindNextFile(); if ( OneFile.IsDirectory() && !OneFile.IsDots() ) //如果查找的结果是目录又不是".."或"."
{
//向Tree1中添加目录;
DirName = OneFile.GetFilePath();
FName = OneFile.GetFileTitle();
//IDC_TREE1
NewItem = m_Tree.InsertItem( FName, faItem ); //NewItem取得节点,其目的是为了下一层中
//添加节点方便,递归时把它传过去。
//进入下一层递归调用。
AddFile(DirName, NewItem);
} //退出递归时,到了这里!!!
if ( !OneFile.IsDirectory() && !OneFile.IsDots() ) //如果查找结果是文件
{
//向Tree1中添加文件
FName = OneFile.GetFileTitle(); //注意这里用的是GetFileTitle,因为
//这里是添加文件。
m_Tree.InsertItem( FName, faItem );
}
}// end of while
OneFile.Close(); //记着用完CFileFild实例要关闭
}
The following sample console application illustrates the use of ShellExecuteEx. Most error checking code has been omitted for clarity.#include <shlobj.h>
#include <shlwapi.h>main()
{
LPMALLOC pMalloc;
LPITEMIDLIST pidlWinFiles = NULL;
LPITEMIDLIST pidlItems = NULL;
IShellFolder *psfWinFiles = NULL;
IShellFolder *psfDeskTop = NULL;
LPENUMIDLIST ppenum = NULL;
STRRET strDispName;
TCHAR pszParseName[MAX_PATH];
ULONG celtFetched;
SHELLEXECUTEINFO ShExecInfo;
HRESULT hr;
BOOL fBitmap = FALSE; hr = SHGetMalloc(&pMalloc);
hr = SHGetFolderLocation(NULL, CSIDL_WINDOWS, NULL, NULL, &pidlWinFiles); hr = SHGetDesktopFolder(&psfDeskTop); hr = psfDeskTop->BindToObject(pidlWinFiles, NULL, IID_IShellFolder, (LPVOID *) &psfWinFiles);
hr = psfDeskTop->Release(); hr = psfWinFiles->EnumObjects(NULL,SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &ppenum); while( hr = ppenum->Next(1,&pidlItems, &celtFetched) == S_OK && (celtFetched) == 1)
{
psfWinFiles->GetDisplayNameOf(pidlItems, SHGDN_FORPARSING, &strDispName);
StrRetToBuf(&strDispName, pidlItems, pszParseName, MAX_PATH);
pMalloc->Free(pidlItems);
if(StrCmpI(PathFindExtension(pszParseName), TEXT( ".bmp")) == 0)
{
fBitmap = TRUE;
break;
}
}
ppenum->Release(); if(fBitmap)
{
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = NULL;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = pszParseName;
ShExecInfo.lpParameters = NULL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_MAXIMIZE;
ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo);
} pMalloc->Free(pidlWinFiles);
pMalloc->Release();
psfWinFiles->Release(); return 0;
}