标签:
代码如下:
1 // csFilePath 文件路径,以|分隔。 nPathes 路径数。
2 void CGetDirectoryDlg::ShowPropertiesByPath(CString csFilePath,int nPathes)
3 {
4 if(csFilePath.IsEmpty())
5 {
6 return;
7 }
8 //单个文件属性
9 if(nPathes == 1)
10 {
11 SHELLEXECUTEINFO sei;
12 ZeroMemory(&sei,sizeof(sei));
13 sei.cbSize = sizeof(SHELLEXECUTEINFO);
14 sei.hwnd = m_hWnd;
15 sei.lpParameters = NULL;
16 sei.nShow = 0;
17 sei.lpIDList = NULL;
18 sei.hInstApp = 0;
19 sei.lpFile = csFilePath;//要显示属性的文件
20 sei.lpVerb = L"properties";
21 sei.fMask = SEE_MASK_IDLIST | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_INVOKEIDLIST |
22
23 SEE_MASK_FLAG_NO_UI;
24 ShellExecuteEx(&sei);
25 return;
26 }
27
28 //多个文件属性
29 LPITEMIDLIST *pidlDrives = (LPITEMIDLIST *)malloc(sizeof(LPITEMIDLIST)*nPathes);
30 IShellFolder* psfDesktop;
31 IDataObject* pData;
32 HRESULT hr;
33 ULONG chEaten=0, dwAttributes=0;
34 int i=0;
35 hr = SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, pidlDrives);
36 if (SUCCEEDED(hr))
37 {
38 hr = SHGetDesktopFolder(&psfDesktop);
39 do{
40 CString currentFilePath;
41 int delimitatorPosition;
42 delimitatorPosition = csFilePath.Find(L‘|‘);
43 if(delimitatorPosition == -1)
44 {
45 delimitatorPosition = csFilePath.GetLength();
46 }
47 currentFilePath = csFilePath.Left(delimitatorPosition);
48 csFilePath.Delete(0, delimitatorPosition + 1);
49 psfDesktop->ParseDisplayName(NULL,
50 NULL,
51 currentFilePath.GetBuffer(),
52 &chEaten,
53 (LPITEMIDLIST*)&pidlDrives[i],
54 &dwAttributes);
55 i++;
56 }while(!csFilePath.IsEmpty() && i<nPathes);
57
58 if (SUCCEEDED(hr))
59 {
60 hr = psfDesktop->GetUIObjectOf(NULL,
61 nPathes,
62 (LPCITEMIDLIST*)pidlDrives,
63 IID_IDataObject,
64 NULL,
65 (void**)&pData);
66 if (SUCCEEDED(hr))
67 {
68 CoInitialize(NULL);
69 hr = SHMultiFileProperties(pData,0);
70 if(SUCCEEDED(hr))
71 {
72 pData->Release();
73 }
74 CoUninitialize();
75 }
76 if(psfDesktop != NULL)
77 {
78 psfDesktop->Release();
79 }
80 }
81 for(i=0;i<nPathes;i++)
82 {
83 ILFree(pidlDrives[i]);
84 }
85 }
86 }
87
88 //调用方法:ShowPropertiesByPath(L"D:\\Share\\v.txt|D:\\Share\\sh.txt", 2);
调用windows api SHMultiFileProperties 显示多文件的汇总属性
标签:
原文地址:http://www.cnblogs.com/freemindblog/p/5674550.html