static int CALLBACK BrowseCallbakProc(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM pData)
{
switch(uMsg)
{
case BFFM_VALIDATEFAILED:
CString strText;
strText.Format("%s", reinterpret_cast<LPTSTR>(lParam));
AfxMessageBox(strText);
break;
}
return 0;
};
void CTest3Dlg::OnButton1()
{
ITEMIDLIST *pildBrowse;
char pszPathname[MAX_PATH];
LPITEMIDLIST pidl = NULL;
BROWSEINFO bInfo;
ZeroMemory( &bInfo, sizeof(BROWSEINFO) );
SHPathToPidl( "C:\\DownLoad", &pidl ); //이곳에 최상위 루트를 지정하시구요
bInfo.hwndOwner = GetSafeHwnd();
bInfo.pidlRoot = pidl;
bInfo.pszDisplayName = pszPathname;
bInfo.lpszTitle = "디렉토리를 선택하세요";
bInfo.lpfn = BrowseCallbakProc; //에디트 박스에서 텍스트를 받아오기 위한 Callback 입니다.
bInfo.ulFlags = BIF_BROWSEINCLUDEFILES | BIF_EDITBOX | BIF_VALIDATE;
pildBrowse = ::SHBrowseForFolder(&bInfo);
if( pildBrowse != NULL )
{
SHGetPathFromIDList(pildBrowse, pszPathname);
CString m_strFolder = (LPCTSTR)pszPathname;
MessageBox( m_strFolder );
}
}
HRESULT CTest3Dlg::SHPathToPidl( LPCTSTR szPath, LPITEMIDLIST* ppidl )
{
LPSHELLFOLDER pShellFolder = NULL;
OLECHAR wszPath[MAX_PATH] = {0};
ULONG nCharsParsed = 0;
HRESULT hr = SHGetDesktopFolder( &pShellFolder );
if( FAILED(hr) )
return FALSE;
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szPath, -1, wszPath, MAX_PATH );
hr = pShellFolder->ParseDisplayName( NULL, NULL, wszPath, &nCharsParsed, ppidl, NULL );
pShellFolder->Release();
return hr;
}
'Programming > MFC' 카테고리의 다른 글
trl::shared_ptr 사용방법 (0) | 2008.01.10 |
---|---|
MessgeBox 졸료하기 (0) | 2008.01.08 |
SDI 폼뷰에 다중뷰 넣기 (0) | 2007.11.09 |
시스템의 종료/재부팅/로그오프 (Shutdown/Rebooting/Logooff) (0) | 2007.11.03 |
WM_QUERYENDSESSION메세지로 운영체체 종료 알림 (0) | 2007.11.03 |