//选择目录
void CDemoDlg::OnClickedButtonFolder()
{
char szPath[MAX_PATH];
m_folder.GetWindowTextA(szPath, MAX_PATH);
BROWSEINFO bi={};
bi.hwndOwner=m_hWnd;
bi.lpszTitle="请选择输入目录";
bi.lpfn=CDemoDlg::BrowseCallbackProc;
bi.lParam=long(&szPath); //选择目录对话框弹出时的默认目录
LPITEMIDLIST lp=SHBrowseForFolder(&bi);
if(lp && SHGetPathFromIDList(lp, szPath))
{
m_folder.SetWindowTextA(szPath);
}
}
//选择目录对话框的回调函数
int CALLBACK CDemoDlg::BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lParam,LPARAM lpData)
{
switch(uMsg)
{
case BFFM_INITIALIZED: //选择目录对话框初始化时 选中指定目录
::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,lpData);
break;
default:
break;
}
return 0;
}