IShellFolder浏览文件夹

这是由IShellFolder接口提供的浏览文件夹功能:

void SpecialFolder_Browse(HWND hwnd)

{
	LPMALLOC g_pMalloc;
	/* Gets the Shell's default allocator */
	if (::SHGetMalloc(&g_pMalloc) == NOERROR)
	{
		BROWSEINFO bi; 
		LPTSTR lpBuffer;
		LPITEMIDLIST pidlSpecialFolder;  // PIDL for Special Folder
		LPITEMIDLIST pidlBrowse;         // PIDL selected by user 

		// Allocate a buffer to receive browse information. 
		if ((lpBuffer = (LPTSTR) g_pMalloc->Alloc(MAX_PATH)) != NULL) 
		{ 
			// Get the PIDL for the Programs folder. 
			if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_DESKTOP/*CSIDL_DESKTOPDIRECTORY*/ , &pidlSpecialFolder)))
			{ 
				// Fill in the BROWSEINFO structure. 
				bi.hwndOwner = hwnd; 
				bi.pidlRoot = pidlSpecialFolder; 
				bi.pszDisplayName = lpBuffer; 
				bi.lpszTitle = _T("Choose a Program Group"); 
				bi.ulFlags = 0; 
				bi.lpfn = NULL; 
				bi.lParam = 0; 

				// Browse for a folder and return its PIDL. 
				pidlBrowse = SHBrowseForFolder(&bi); 
				if (pidlBrowse != NULL) 
				{  
					// Show the display name, title, and file system path. 
					::MessageBox(hwnd, lpBuffer, L"Display name", MB_OK); 
					if (SHGetPathFromIDList(pidlBrowse, lpBuffer)) //SHGetPathFromIDList获得pidlBrowse的全路径保存在缓存中
 						MessageBox(lpBuffer); 

					// Free the PIDL returned by SHBrowseForFolder. 
					g_pMalloc->Free(pidlBrowse); 
				} 

				// Clean up. 
				g_pMalloc->Free(pidlSpecialFolder); 
			}
			g_pMalloc->Free(lpBuffer); 
		}

		// Release the shell's allocator.
		g_pMalloc->Release();
	}
}


原文链接:http://blog.csdn.net/zgl7903/article/details/2577729

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值