{
//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
else if( uMsg == BFFM_SELCHANGED )
{
//BFFM_SELCHANGED消息中,lpData 指向新选择的目录的PIDL
LPITEMIDLIST pidl = (LPITEMIDLIST) lParam
char selection[MAX_PATH]
//调用SHGetPathFromIDList从PIDL转换为文件系统路径字符串
if( ! ::SHGetPathFromIDList(pidl, selection) )
selection[0] = '\0'
CString csStatusText
//调用SelChanged函数,由CDirDialog或其派生类重载的SelChanged函数来决定是否允许选择该目录
BOOL bOk = pDirDialogObj->SelChanged(selection, csStatusText)
if( pDirDialogObj->m_bStatus )
//修改浏览目录的对话框的状态栏内容为新选择的目录路径
::SendMessage(hwnd, BFFM_SETSTATUSTEXT , 0, (LPARAM)(LPCSTR)csStatusText)
//如果SelChanged返回TRUE,表示允许选择该目录,于是启用"确定"按钮,否则禁用。
::SendMessage(hwnd, BFFM_ENABLEOK, 0, bOk)
}
return 0
}
你这么写肯定不对的if(filedlg.DoModal()==IDOK)
{
CString fileName=filedlg.GetFileName()
m_FileName=fileName
UpdateData(FALSE)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)