打开文件夹
void CCFileBrowerDemoDlg::OpenFileFolder()
{
TCHAR szPath[MAX_PATH] = {0};
BROWSEINFO bi = {0};
bi.hwndOwner = this->GetSafeHwnd();
bi.lpszTitle = TEXT("请选择文件夹");
bi.ulFlags = BIF_RETURNONLYFSDIRS;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
if (pidl == NULL)
{
return;
}
if (SHGetPathFromIDList(pidl, szPath))
{
// szPath为选择的文件的全路径
//SetDlgItemText(IDC_FILEPATH, pszPath);
}
}
打开文件
void CCFileBrowerDemoDlg::OpenDefinedFile()
{
static CString strPath = _T("");
// TODO: Add your control notification handler code here
TCHAR szBuf[10240] = {0};
CString strFilter = _T("PNG(*.png)|*.png|BMP(*.bmp)|*.bmp|All Files(*.*)|*.*|");
DWORD dwFlags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_ALLOWMULTISELECT;
CFileDialog OpenDlg(TRUE, NULL, NULL, dwFlags, strFilter, this);
OpenDlg.m_ofn.lpstrFile = szBuf;
OpenDlg.m_ofn.nMaxFile = 10240;
OpenDlg.m_ofn.lpstrInitialDir = strPath;
if (IDOK == OpenDlg.DoModal())
{
POSITION pos = OpenDlg.GetStartPosition();
CString strFullPath = _T(""); // 完整路径,路径 + 文件名
int nItem = 0;
while (pos)
{
strFullPath = OpenDlg.GetNextPathName(pos);
}
}
}