Programming/MFC-C++

MFC 폴더 선택 Dialog

빠릿베짱이 2013. 4. 24. 18:31
반응형

int CALLBACK BrowseCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{    
	CHAR lpszDir[255];   
	switch(uMsg)   
	{    
	case BFFM_INITIALIZED: 
		SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);   
		break;   
	case BFFM_SELCHANGED:   
		if(SHGetPathFromIDList((LPITEMIDLIST)lParam, lpszDir))     
			SendMessage(hwnd, BFFM_SETSTATUSTEXT,0, (LPARAM)lpszDir);       
		break;  
  }  
	return 0;
}



//원하는 이벤트 핸들러에 추가
	ITEMIDLIST *pidlBrowse;   
	WCHAR   pszPathname[MAX_PATH];
	BROWSEINFO BrInfo;
   	BrInfo.hwndOwner = GetSafeHwnd(); 
	BrInfo.pidlRoot = NULL;  
	CString str = "c:\\depth";    //초기 디렉토리 설정
	LPCTSTR lpszDefaultFolder = str; 
	memset(&BrInfo, 0, sizeof(BrInfo)); 
	BrInfo.pszDisplayName  = (LPSTR)pszPathname; 
	BrInfo.lpszTitle   = _T("Select directory");  
	BrInfo.ulFlags    = BIF_RETURNONLYFSDIRS; //폴더만 선택 가능
    	BrInfo.ulFlags = BIF_BROWSEINCLUDEFILES; //디렉토리와 파일까지 선택가능
    	BrInfo.lParam = (LPARAM)lpszDefaultFolder;   
	BrInfo.lpfn = BrowseCallback;                
	pidlBrowse = ::SHBrowseForFolder(&BrInfo);  
	if (pidlBrowse != NULL)    // 폴더 선택이 완료되면
	{     
		//Get Path      
		SHGetPathFromIDList(pidlBrowse, (LPSTR)pszPathname); 
		m_strFolderName.Format("%s",pszPathname);		
	}

반응형