VC选择文件和文件夹。

1,选择文件夹

void CDialog::OnButtonBrowser()

{

       // TODO: Add your control notification handler code here

       UpdateData(TRUE);

       char szDir[MAX_PATH];

       BROWSEINFO bi;

       ITEMIDLIST *pidl;

       bi.hwndOwner = this->m_hWnd;

       bi.pidlRoot = NULL;

       bi.pszDisplayName = szDir;

       bi.lpszTitle = "请选择目录";

       bi.ulFlags = BIF_STATUSTEXT | BIF_USENEWUI | BIF_RETURNONLYFSDIRS;

       bi.lpfn = NULL;

       bi.lParam = 0;

       bi.iImage = 0;

       pidl = SHBrowseForFolder(&bi);

       if(pidl == NULL)  return;

       if(!SHGetPathFromIDList(pidl, szDir))   return;

       else  m_strPath = szDir;

       UpdateData(FALSE);    

}

 

 

2、选择文件

char szFilter[]="Text files(*.txt)|*.txt";

 CFileDialog dlg(1,NULL,NULL,NULL,szFilter);

 if(dlg.DoModal()==IDOK)
 {
        m_sRtDataFilePath = dlg.GetPathName();
 }

 

3

获取打开文件GetOpenFileName
获取保存文件GetSaveFileName

你可能感兴趣的:(文件夹)