㈠ MFC中获取文件名及路径实现方法——DirDialog类中的BrowseCtrlCallback注释翻译
int__stdcallCDirDialog::BrowseCtrlCallback(HWNDhwnd,UINTuMsg,LPARAMlParam,LPARAMlpData)
{
//bInfo.lParam=(LPARAM)this;这行代码将CDirDialog对象通过lpData传入到回调函数BrowseCtrlCallback
CDirDialog*pDirDialogObj=(CDirDialog*)lpData;
//浏览目录的对话框已初始化完成后会回调BrowseCtrlCallback,uMsg等于BFFM_INITIALIZED
if(uMsg==BFFM_INITIALIZED)
{
//如果指定了默认目录,给hwnd(浏览目录对话框)发送BFFM_SETSELECTION消息,用于自动选中该默认目录
if(!pDirDialogObj->m_strSelDir.IsEmpty())
::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)(LPCTSTR)(pDirDialogObj->m_strSelDir));
//如果CDirDialog的m_strWindowTitle不是空字符串,那么将浏览目录对话框的窗口标题设置为m_strWindowTitle
if(!pDirDialogObj->m_strWindowTitle.IsEmpty())
::SetWindowText(hwnd,(LPCTSTR)pDirDialogObj->m_strWindowTitle);
}
//浏览目录的对话框内用户选择的目录变化时,回调BrowseCtrlCallback,uMsg等于BFFM_SELCHANGED
elseif(uMsg==BFFM_SELCHANGED)
{
//BFFM_SELCHANGED消息中,lpData指向新选择的目录的PIDL
LPITEMIDLISTpidl=(LPITEMIDLIST)lParam;
charselection[MAX_PATH];
//调用SHGetPathFromIDList从PIDL转换为文件系统路径字符串
if(!::SHGetPathFromIDList(pidl,selection))
selection[0]='