본문 바로가기

컴퓨터 과학 & 영상처리 관련/MFC

CFileDialog, openFileDialog로 전체경로,파일명,폴더경로,확장자 가져오는거

 

 

이 클래스는 c#이랑 비슷하네..

 

 

전체경로 -  GetPathName()

파일명 - GetFileName() - 5.jpg

폴더경로 - GetFolderPath() - 이건 마지막에 \\써서 쓰면 될듯

확장자 - GetFileExt() - 확장자만 jpg 딱

 

 

 

 

 

 

 char szFilter[] = "Image (*.BMP, *.GIF, *.JPG) | *.BMP;*.bmp;*.GIF;*.gif;*.JPG;*.jpg | All Files(*.*)|*.*||";
 
 CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter);


OFN_ALLOWMULTISELECT인가 하면 멀티 셀렉트 가능

dlg.m_ofn.lpstrInitialDir = _T(getDesktopFolderName());


 
 if(IDOK == dlg.DoModal()) {
   CString strPathName = dlg.GetPathName();
  
  strPathName.AppendFormat("\n\n%s",dlg.GetFileName());
  strPathName.AppendFormat("\n\n%s",dlg.GetFolderPath());
  strPathName.AppendFormat("\n\n%s",dlg.GetFileExt());

  AfxMessageBox(strPathName);
 }


150702-----------------------

http://stackoverflow.com/questions/1107913/select-multiple-files-in-cfiledialog