浏览文件夹,其实用的是Shell里的API
void OnXXXBrowse()
{
CString strFolderPath;
BROWSEINFO broInfo = {0};
TCHAR szDisName[MAX_PATH] = {0};
broInfo.hwndOwner = this->m_hWnd;
broInfo.pidlRoot = NULL;
broInfo.pszDisplayName = szDisName;
broInfo.lpszTitle = _T("选择保存路径");
broInfo.ulFlags = BIF_NEWDIALOGSTYLE | BIF_DONTGOBELOWDOMAIN
| BIF_BROWSEFORCOMPUTER | BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS;
broInfo.lpfn = NULL;
broInfo.lParam = NULL;
broInfo.iImage = IDR_MAINFRAME;
LPITEMIDLIST pIDList = SHBrowseForFolder(&broInfo);
if (pIDList != NULL)
{
memset(szDisName, 0, sizeof(szDisName));
SHGetPathFromIDList(pIDList, szDisName);
strFolderPath = szDisName;
}
}
浏览保存文件
void BrowseSaveFile()
{
LPCTSTR szFilter = _T("puk files(*.puk)|*.puk||");
// CFileDialog的第一个参数标明是浏览还是保存
CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilter);
if (dlg.DoModal() == IDOK)
{
CString fileName = dlg.GetPathName();
}
}
获取当前路径
void GetCurPath()
{
CString strCurPath; // 不包含文件名的全路径
GetModuleFileName(NULL, strCurPath.GetBufferSetLength(MAX_PATH + 1), MAX_PATH);
strCurPath.ReleaseBuffer();
int nPos = strCurPath.ReverseFind('\\');
strCurPath = strCurPath.Left(nPos + 1);
}