1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
void CInitControl::OnBrowse()
{
// TODO: Add your control notification handler code here
CString strFolderPath;
GetFolder(&strFolderPath, "Sample of getting folder.", this->m_hWnd, NULL, NULL);
CEdit *experiment=(CEdit*)GetDlgItem(IDC_EXPERIMENT);
experiment->SetWindowText(strFolderPath);
}
void CInitControl::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, (LPCTSTR)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 = 0;
if (strStartFolder == NULL)
{
bi.lParam = FALSE;
}
else
{
strTmpPath.Format("%s", strStartFolder);
bi.lParam = TRUE;
}
bi.iImage = NULL;
lpID = SHBrowseForFolderA(&bi);
if (lpID != NULL){
BOOL b = SHGetPathFromIDList(lpID, pszDisplayName);
if (b == TRUE)
{
strSelectedFolder->Format("%s",pszDisplayName);
}
}
else
{
strSelectedFolder->Empty();
}
} |
Partager