Programming/MFC-C++

MFC 폴더 선택 다이얼로그 창 띄우기

빠릿베짱이 2013. 1. 7. 23:02
반응형
void CKinect4WinDlg::OnBnClickedSetfolder()
{
	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);
		AfxMessageBox((LPCSTR)pszPathname);
		
	}
}

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;
}

반응형