㈠ 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]='