int BrowseCallbackProc(HWND hwnd, UINT msg, LPARAM lp, LPARAM pData)
{
// m_strInitDir为初始化目录
if (!m_strInitDir.empty())
{
if (msg == BFFM_INITIALIZED)
{
::SendMessage(hwnd,BFFM_SETEXPANDED,TRUE,(LPARAM)m_strInitDir.c_str());
}
else if (msg == BFFM_SELCHANGED && bFirst)
{
bFirst = false;
::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)m_strInitDir.c_str());
}
}
return 0;
}
void ShowGetDirectoryDialog(HWND m_handle)
{
bFirst = true;
wchar_t szDir[MAX_PATH/2];
BROWSEINFO bi;
ITEMIDLIST* pidl = NULL;
bi.hwndOwner = m_handle;
bi.pidlRoot = NULL;
bi.pszDisplayName = szDir;
bi.lpszTitle = L"请选择文件夹";
bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS;
bi.lpfn = BrowseCallbackProc; // 回调函数,状态改变时调用该函数
bi.lParam = 0;
bi.iImage = 0;
pidl = SHBrowseForFolder(&bi);
}