CString C_strTmpPath;
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
TCHAR szDir[MAX_PATH];
switch(uMsg)
{
case BFFM_INITIALIZED:
if (lpData)
{
strcpy((LPSTR)szDir, (LPSTR)C_strTmpPath.GetBuffer(C_strTmpPath.GetLength()));
SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)szDir);
}
break;
case BFFM_SELCHANGED:
{
if (SHGetPathFromIDList((LPITEMIDLIST) lParam ,szDir))
{
SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir);
}
break;
}
default:
break;
}
return 0;
}
BOOL GetFolder(CString* strSelectedFolder,const char* lpszTitle,const HWND hwndOwner,const char* strRootFolder,const char* strStartFolder)
{
char pszDisplayName[MAX_PATH];
LPITEMIDLIST lpID;
BROWSEINFOA bi;
bi.hwndOwner = hwndOwner;
if (strRootFolder == NULL)
{
bi.pidlRoot = NULL;
}
else
{
LPITEMIDLIST pIdl = NULL;
IShellFolder* pDesktopFolder;
char szPath[MAX_PATH];
OLECHAR olePath[MAX_PATH];
ULONG chEaten;
ULONG dwAttributes;
strcpy(szPath, strRootFolder);
if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
{
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szPath, -1, olePath, MAX_PATH);
pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, &pIdl, &dwAttributes);
pDesktopFolder->Release();
}
bi.pidlRoot = pIdl;
}
bi.pszDisplayName = pszDisplayName;
bi.lpszTitle = lpszTitle;
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
bi.lpfn = BrowseCallbackProc;
if (strStartFolder == NULL)
{
bi.lParam = FALSE;
}
else
{
C_strTmpPath.Format(_T("%s"), strStartFolder);
bi.lParam = TRUE;
}
bi.iImage = NULL;
lpID = SHBrowseForFolderA(&bi);
if (lpID != NULL)
{
BOOL b = SHGetPathFromIDList(lpID, (LPWSTR)pszDisplayName);
if (b == TRUE)
{
strSelectedFolder->Format(_T("%s"),pszDisplayName);
return TRUE;
}
}
else
{
strSelectedFolder->Empty();
}
return FALSE;
}
void CDlgSetting::OnBnClickedBtnBrowse()
{
// TODO: Add your control notification handler code here
GetFolder(&m_sFoldePath,(""),this->m_hWnd,NULL,NULL);
UpdateData( FALSE );
}