//添加回调函数记录上次打开的目录
static std::string g_lastSelDir;
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT msg, LPARAM lp, LPARAM pData)
{
if (msg == BFFM_INITIALIZED )
{
::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)g_lastSelDir.c_str());
}
return 0;
}
char szPath[MAX_PATH]; //存放选择的目录路径
CString str;
ZeroMemory(szPath, sizeof(szPath));
BROWSEINFO bi;
bi.hwndOwner = m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szPath;
bi.lpszTitle = "请选择提取文件保存的目录:";
bi.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_EDITBOX;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
//弹出选择目录对话框
LPITEMIDLIST lp = SHBrowseForFolder(&bi);
if(lp && SHGetPathFromIDList(lp, szPath))
{
str.Format("选择的目录为 %s", szPath);
g_lastSelDir = str.getbuffer(0);
AfxMessageBox(str);
}
else
AfxMessageBox("无效的目录,请重新选择");