내가 수정 했던 소스
INT CALLBACK BrowseCallbackProc (HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
switch (uMsg)
{
case BFFM_INITIALIZED:
SendMessage (hWnd, BFFM_SETSELECTION, TRUE, lpData);
break;
}
return 0;
}
void CPreferenceDlg::OnBtnPath()
{
TCHAR tszDisplayName[MAX_PATH*10];
GetCurrentDirectory(MAX_PATH*10, tszDisplayName);\
LPITEMIDLIST pDirList;
CString str = _T("백업 파일을 저장할 폴더를 선택하세요.");
BROWSEINFO binfo;
ZeroMemory(&binfo, sizeof(BROWSEINFO));
binfo.hwndOwner = m_hWnd;
binfo.pidlRoot = NULL;
binfo.lpszTitle = str;
//binfo.ulFlags = BIF_NONEWFOLDERBUTTON | BIF_RETURNONLYFSDIRS;//BIF_NONEWFOLDERBUTTON |
// 새폴더 만들기 버튼 생성위한 플래그
binfo.ulFlags = 0x0040 | 0x0100 | BIF_EDITBOX | BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
binfo.lpfn = BrowseCallbackProc;
binfo.lParam = (LPARAM) tszDisplayName;
pDirList = SHBrowseForFolder(&binfo);
if(pDirList != NULL)
{
if (!SHGetPathFromIDList(pDirList, tszDisplayName))
return;
CString strDirName(tszDisplayName);
strDirName.TrimRight(_T("\\"));
m_cEditPath.SetWindowText(strDirName);
}
}
--------------------------------------------------------------------
아래는 웹에서 찾았던 것들
// 기본으로 열기
void CShell_003ADlg::OnButton1()
{
BROWSEINFO bi;
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = this->GetSafeHwnd();
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
TCHAR szPath[MAX_PATH] = {0};
SHGetPathFromIDList(pidl, szPath);
SetDlgItemText(IDC_STATIC_1, szPath);
}
// 기본으로 열기1
void CShell_003ADlg::OnButton2()
{
BROWSEINFO bi;
TCHAR szBuff[MAX_PATH] = {0};
TCHAR szDisp[MAX_PATH] = {0};
lstrcpy(szBuff, "Choose a folder : ");
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = this->GetSafeHwnd();
bi.lpszTitle = static_cast(szBuff);
bi.pszDisplayName = static_cast(szDisp);
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
TCHAR szPath[MAX_PATH] = {0};
SHGetPathFromIDList(pidl, szPath);
CString a = CString(bi.pszDisplayName).Right(1);
if(a== _T(")"))
SetDlgItemText(IDC_STATIC_2, bi.pszDisplayName);
else
SetDlgItemText(IDC_STATIC_2, szPath);
SendDlgItemMessage(IDC_STATIC_ICON_1, STM_SETICON, reinterpret_cast(SHGetSystemIcon(bi.iImage)));
}
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT msg, LPARAM l, LPARAM ld)
{
switch(msg){
case BFFM_SELCHANGED:{
TCHAR pass[MAX_PATH] = {0};
SHGetPathFromIDList(reinterpret_cast(l), pass);
SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, reinterpret_cast(pass));
}
}
return 0;
}
// 기본으로 열기 2
void CShell_003ADlg::OnButton3()
{
BROWSEINFO bi;
TCHAR szBuff[MAX_PATH] = {0};
lstrcpy(szBuff, "Choose a folder : ");
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = this->GetSafeHwnd();
bi.lpszTitle = static_cast(szBuff);
bi.ulFlags = static_cast(BIF_STATUSTEXT);
bi.lpfn = BrowseCallbackProc;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
TCHAR szPath[MAX_PATH] = {0};
SHGetPathFromIDList(pidl, szPath);
SetDlgItemText(IDC_STATIC_3, szPath);
}
// 프린터 폴더 열기
void CShell_003ADlg::OnButton4()
{
BROWSEINFO bi;
LPITEMIDLIST pidl;
ZeroMemory(&bi, sizeof(BROWSEINFO));
SHGetSpecialFolderLocation(NULL, CSIDL_PRINTERS, &pidl);
bi.hwndOwner = this->GetSafeHwnd();
bi.pidlRoot = pidl;
bi.ulFlags = BIF_BROWSEINCLUDEFILES;
SHBrowseForFolder(&bi);
}
// 즐겨찾기 폴더 열기
void CShell_003ADlg::OnButton5()
{
BROWSEINFO bi;
LPITEMIDLIST pidl;
ZeroMemory(&bi, sizeof(BROWSEINFO));
SHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl);
bi.hwndOwner = this->GetSafeHwnd();
bi.pidlRoot = pidl;
bi.ulFlags = BIF_BROWSEINCLUDEFILES;
SHBrowseForFolder(&bi);
}
// 네트워크 폴더 열기
void CShell_003ADlg::OnButton6()
{
BROWSEINFO bi;
LPITEMIDLIST pidl;
ZeroMemory(&bi, sizeof(BROWSEINFO));
SHGetSpecialFolderLocation(NULL, CSIDL_NETWORK, &pidl);
bi.hwndOwner = this->GetSafeHwnd();
bi.pidlRoot = pidl;
bi.ulFlags = BIF_BROWSEINCLUDEFILES;
SHBrowseForFolder(&bi);
}
// 휴지통 폴더 열기
void CShell_003ADlg::OnButton7()
{
BROWSEINFO bi;
LPITEMIDLIST pidl;
ZeroMemory(&bi, sizeof(BROWSEINFO));
SHGetSpecialFolderLocation(NULL, CSIDL_BITBUCKET, &pidl);
bi.hwndOwner = this->GetSafeHwnd();
bi.pidlRoot = pidl;
bi.ulFlags = BIF_BROWSEINCLUDEFILES;
SHBrowseForFolder(&bi);
}
// 폰트 폴더 열기
void CShell_003ADlg::OnButton8()
{
BROWSEINFO bi;
LPITEMIDLIST pidl;
ZeroMemory(&bi, sizeof(BROWSEINFO));
SHGetSpecialFolderLocation(NULL, CSIDL_FONTS, &pidl);
bi.hwndOwner = this->GetSafeHwnd();
bi.pidlRoot = pidl;
bi.ulFlags = BIF_BROWSEINCLUDEFILES;
SHBrowseForFolder(&bi);
}
// 제어판 폴더 열기
void CShell_003ADlg::OnButton9()
{
BROWSEINFO bi;
LPITEMIDLIST pidl;
ZeroMemory(&bi, sizeof(BROWSEINFO));
SHGetSpecialFolderLocation(NULL, CSIDL_CONTROLS, &pidl);
bi.hwndOwner = this->GetSafeHwnd();
bi.pidlRoot = pidl;
bi.ulFlags = BIF_BROWSEINCLUDEFILES;
SHBrowseForFolder(&bi);
}
HRESULT CShell_003ADlg::SHSetPathToPidl(LPCTSTR szPath, LPITEMIDLIST* ppidl)
{
LPSHELLFOLDER pShellFolder = NULL;
OLECHAR wszPath[MAX_PATH] = {0};
ULONG nCharParsed = 0;
HRESULT hr = SHGetDesktopFolder(&pShellFolder);
if(FAILED(hr))
return hr;
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szPath, -1, wszPath, MAX_PATH);
hr = pShellFolder->ParseDisplayName(NULL, NULL, wszPath, &nCharParsed, ppidl, NULL);
pShellFolder->Release();
return hr;
}
// 임의의 폴더를 루트로
void CShell_003ADlg::OnButton10()
{
BROWSEINFO bi;
LPITEMIDLIST pidl;
CString tPath = _T("D:\\Program Files\\");
ZeroMemory(&bi, sizeof(BROWSEINFO));
if(FAILED(SHSetPathToPidl((LPCTSTR)tPath, &pidl)))
return;
bi.hwndOwner = this->GetSafeHwnd();
bi.pidlRoot = pidl;
bi.ulFlags = BIF_BROWSEINCLUDEFILES;
SHBrowseForFolder(&bi);
}