/*
文件名:IShellFolder.Cpp
功能:列出桌面的所以的(子)文件和(子)文件夹.
至今方知目录和文件夹的区别.
Windows Shell一直是一个知道但不熟悉的名字.
Windows Shell搞懂了,再搞COM等.
参考示例:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776885(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776889(v=vs.85).aspx
made by correy
made at 2013.11.18
email:kouleguan at hotmail dot com
homepage:http://correy.webs.com
不足之处,敬请指出.
*/
#include <shlobj.h>
#pragma comment(lib, "shlwapi.lib")
int main()
{
IShellFolder *psfDeskTop = NULL;
HRESULT hr = SHGetDesktopFolder(&psfDeskTop);//获取对象的地址.
LPENUMIDLIST ppenum = NULL;
hr = psfDeskTop->EnumObjects(NULL,SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &ppenum);//获取对象的地址.
ULONG celtFetched;
LPITEMIDLIST pidlItems = NULL;
while( hr = ppenum->Next(1,&pidlItems, &celtFetched) == S_OK && (celtFetched) == 1) //获取pidlItems
{
STRRET strDispName;
psfDeskTop->GetDisplayNameOf(pidlItems, SHGDN_INFOLDER, &strDispName);//获取strDispName
MessageBox(0,strDispName.pOleStr,0,0);
CoTaskMemFree(pidlItems);
}
ppenum->Release();
return 0;
}
没有评论:
发表评论