static int __stdcall BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
LPCTSTR lpszInitPath = (LPCTSTR)lpData;
if (uMsg == BFFM_INITIALIZED && !g_strInitPath.IsEmpty())
{
::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)lpszInitPath);
}
return 0;
}
下面的函数演示了选择文件夹的操作,代码有点乱,贴到VC的IDE中就好了
void CLeftView::OnBtnBrowse()
{
GetDlgItem(IDC_EDIT_PATH)-> GetWindowText(g_strInitPath);
LPMALLOC pMalloc;
CString strPath;
if(SHGetMalloc(&pMalloc) == NOERROR)
{
BROWSEINFO bInfo;
ZeroMemory ( (PVOID) &bInfo,sizeof (BROWSEINFO));
bInfo.hwndOwner = NULL;
bInfo.pszDisplayName = strPath.GetBuffer (MAX_PATH);
bInfo.lpszTitle = _T( "选择搜索范围 "); // 副标题
bInfo.ulFlags = BIF_RETURNONLYFSDIRS|BIF_RETURNFSANCESTORS; // 查找路径
bInfo.lpfn = BrowseCtrlCallback; // 回调函数
bInfo.lParam = (LPARAM)(LPCTSTR)g_strInitPath; // 回调参数
bInfo.iImage = 0; // 返回选择路径图标
LPITEMIDLIST pidl = ::SHBrowseForFolder(&bInfo);
strPath.ReleaseBuffer();
if(pidl != NULL)
{
BOOL bRtn = ::SHGetPathFromIDList(pidl,g_strInitPath.GetBuffer(MAX_PATH));
g_strInitPath.ReleaseBuffer();
if(bRtn)
{
GetDlgItem(IDC_EDIT_PATH)-> SetWindowText(g_strInitPath);
}
pMalloc-> Free(pidl);
}
pMalloc -> Release();
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。