본문 바로가기

Programming/MFC

파일 폴더 오픈 다이얼로그

BROWSEINFO bi;
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner =  this->GetSafeHwnd();
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);

 

if ( pidl == NULL )
  return;

TCHAR szPath[MAX_PATH] = {0};
SHGetPathFromIDList(pidl, szPath); 

 

 

szPath에는 현재 폴더의 경로가 저장된다.

밑에는 원하는 파일의 확장자만 현재 폴더에서 찾아 리스트에 추가하는 코드..

 

 

// Load SDP
void CDHG_2000Doc::LoadSDP()
{
 // Get Frame
 m_pMainFrame = GetMainFrame() ;

 // Get View
 m_pView = GetView() ;

 CString strFilter = m_pMainFrame->GetLoadProfilePathSDP() ;
 CString strFilePath = strFilter ;
 strFilter = strFilter + _T( "\\*.*" ) ;

 //m_file_rtp.clear() ;
 m_file_sdp.clear() ; 

 CFileFind find ;

 BOOL isFile = find.FindFile( strFilter ) ;

 while ( isFile )
 {  
  isFile = find.FindNextFile() ;

  if ( find.IsDots() )
   continue ;

  //if ( find.IsDirectory() )
  {
   CString  ext = _T( "" ) ;
   CString  path = _T( "" ) ;
   CString  dir = _T ( "" ) ;
   CString  file = _T( "" ) ;    
   int   dotCount = 0 ;

   path = find.GetFilePath() ;
   dotCount = path.ReverseFind( _T( '.' ) ) ;
   ext = path.Mid( dotCount+1, path.GetLength() ) ; 
   file = find.GetFileTitle() + '.' + ext ;

   /*if ( ext == "rtp" )
   {  
    FILE_RTP rtp ;    
    rtp.m_rtp_file = file ;
    rtp.m_rtp_path = path ;   

    m_file_rtp.push_back( rtp ) ;
   }
   else*/ if ( ext == "sdp" )
   {
   FILE_SDP sdp ;    
   sdp.m_sdp_file = file ;
   sdp.m_sdp_path = path ;

   m_file_sdp.push_back( sdp ) ;
   }
  }
 }

 // file path save
 m_pMainFrame->SetLoadProfilePathSDP( strFilePath ) ;

 ::SendMessage( m_pView->GetSafeHwnd(), UM_PATTERN, NULL, NULL ) ;
}

'Programming > MFC' 카테고리의 다른 글

윈도우 크기 고정하기 SDI  (0) 2006.08.07
EditBox의 글자 입력수 제한하기  (0) 2006.07.19
Enter key를 눌렀을때 다이얼로그 종료되는 문제 해결  (0) 2006.06.27
SetDlgItemText  (0) 2006.06.26
GetDlgItemText  (0) 2006.06.26