紧急求助~~~~在线等待,分不是问题,要多少给多少,请各位高手帮忙~~~~

cuistar 2003-09-03 09:48:21
给定一个目录,列出其中的所有文件(包括子目录下的文件),要求用对话框实现,要VC源程序全部代码(包括对话框函数对类函数的调用)。
...全文
55 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljan 2003-09-04
  • 打赏
  • 举报
回复
CFileFind没有,不过很简单,操作成员函数就可以了
cuistar 2003-09-04
  • 打赏
  • 举报
回复
谢谢高手,再问一下,有没有用CFileFind来写的程序啊????
ezhou 2003-09-03
  • 打赏
  • 举报
回复
mark.
ljan 2003-09-03
  • 打赏
  • 举报
回复
或者你可以用CFileFind来写
ljan 2003-09-03
  • 打赏
  • 举报
回复
// File.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Shlobj.h"
//#include <comdef.h>
#include <tchar.h>
#include "stdio.h"
#include "conio.h"
//
// This method converts a STRRET structure to a LPTSTR
//
IMalloc* pMalloc;

LONG StrRetToStr(STRRET StrRet, LPTSTR* str, LPITEMIDLIST pidl)
{
HRESULT hr = S_OK;
int cch;
LPSTR strOffset;

*str = NULL; // Assume failure

switch (StrRet.uType)
{
case STRRET_WSTR:
cch = WideCharToMultiByte(CP_OEMCP, 0, StrRet.pOleStr, -1, NULL, 0, NULL, NULL);
*str = (LPTSTR)pMalloc->Alloc(cch * sizeof(TCHAR));

if (*str != NULL)
WideCharToMultiByte(CP_OEMCP, 0, StrRet.pOleStr, -1, *str, cch, NULL, NULL);
else
hr = E_FAIL;
break;

case STRRET_OFFSET:
strOffset = (((char *) pidl) + StrRet.uOffset);

cch = strlen(strOffset) + 1; // NULL terminator
*str = (LPTSTR)pMalloc->Alloc(cch * sizeof(TCHAR));

if (*str != NULL)
strcpy(*str, strOffset);
else
hr = E_FAIL;
break;

case STRRET_CSTR:
cch = strlen(StrRet.cStr) + 1; // NULL terminator
*str = (LPTSTR)pMalloc->Alloc(cch * sizeof(TCHAR));

if (*str != NULL)
strcpy(*str, StrRet.cStr);
else
hr = E_FAIL;

break;
}

return hr;
}

void PrintFile(IShellFolder* pFolder, IMalloc* pMalloc)
{
IEnumIDList* pItems = NULL;
LPITEMIDLIST pidlNext = NULL;
STRRET StrRetName;
LPTSTR lpszName = NULL;

// Enumerate all object in the given folder
HRESULT hr = pFolder->EnumObjects(NULL, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS, &pItems);
while(hr == NOERROR)
{
hr = pItems->Next(1, &pidlNext, NULL);
if(NOERROR == hr)
{
pFolder->GetDisplayNameOf(pidlNext, SHGDN_NORMAL, &StrRetName);
StrRetToStr(StrRetName, &lpszName, pidlNext);

printf("%s ", lpszName);

if(lpszName)
pMalloc->Free(lpszName);
}
}

if(pItems)
pItems->Release();
}

int main(int argc, char* argv[])
{
wchar_t path[MAX_PATH];

printf("请输入文件夹绝对路径:\n");
wscanf(L"%ls", path);

// wprintf(L"%s", path);
CoInitialize(NULL);

// Get a pointer to the IMalloc interface
HRESULT hr = SHGetMalloc(&pMalloc);
if(FAILED(hr))
return hr;

IShellFolder* pDesktop;
hr = SHGetDesktopFolder(&pDesktop);
if(FAILED(hr))
return hr;

ULONG chEaten;
ULONG dwAttributes;
LPITEMIDLIST pidlFolder = NULL;
LPOLESTR strPath = path;
hr = pDesktop->ParseDisplayName(NULL, NULL, strPath, &chEaten,
&pidlFolder, &dwAttributes);
if(FAILED(hr))
return hr;

IShellFolder* pFolder;
hr = pDesktop->BindToObject(pidlFolder, NULL, IID_IShellFolder, (void**)&pFolder);
pDesktop->Release();
if(FAILED(hr))
return hr;

// Print subfolder and file
PrintFile(pFolder, pMalloc);

CoUninitialize();

getch();
return 0;
}

正好是我以前的一个小例子...

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧