MFC文件夹打开的操作

转自:http://wenku.baidu.com/link?url=E3GqYXODm0S3YQxbiImGg1nJeE1ovn396lU-5jdMbOUUyKdv6I8W31zXbaWBmR5W4iBfbJVE7lDDvdjP_jmwOWNUZqz_w6o3uYrqZ29uiym

1.打开文件夹,不做任何选择,只是打开

ShellExecute(NULL, _T("open"), _T("d:\"), NULL, NULL, SW_SHOW); 

2.打开文件夹,选择所选文件夹里面的文件名,格式文件,获取格式文件路径或者格式文件名 CFileDialog dlg(TRUE,NULL,NULL,NULL,NULL); if(dlg.DoModal()==IDOK)// { CString str,str1; str = dlg.GetPathName(); str1 = dlg.GetFileName(); CEdit* cfolder; cfolder = (CEdit*) GetDlgItem(flidersdit); cfolder->SetWindowText(str); // + 1 } 效果图 CFileDialog dlg(TRUE,NULL,NULL,NULL,NULL); if(dlg.DoModal()==IDOK)// { CString str,str1; str = dlg.GetPathName(); str1 = dlg.GetFileName(); CEdit* cfolder; cfolder = (CEdit*) GetDlgItem(flidersdit); cfolder->SetWindowText(str1); // + 1 } 效果图

3,打开文件夹,选择所选择的文件夹,获取文件夹的路径 CString m_FileDir; BROWSEINFO bi; ZeroMemory(&bi, sizeof(BROWSEINFO)); bi.hwndOwner = m_hWnd; bi.ulFlags = BIF_RETURNONLYFSDIRS; LPITEMIDLIST pidl = SHBrowseForFolder(&bi); BOOL bRet = FALSE; TCHAR szFolder[MAX_PATH*2]; szFolder[0] = _T(''); if (pidl) { if (SHGetPathFromIDList(pidl, szFolder)) bRet = TRUE; IMalloc *pMalloc = NULL; if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc) { pMalloc->Free(pidl); pMalloc->Release(); } } m_FileDir = szFolder;//选择的文件夹路径 CEdit* cfolder; cfolder = (CEdit*) GetDlgItem(flidersdit); cfolder->SetWindowText(szFolder); OnPaint(); TRACE(" &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& "); TRACE(m_FileDir); TRACE(" &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ")

原文地址:https://www.cnblogs.com/begoogatprogram/p/5950484.html