XShell.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:3k
- #include "stdAfx.h"
- #include "xshell.h"
- CXShell::CXShell(){}
- CXShell::~CXShell(){}
- //////////////////////////////////////////////////////////////////////////
- int CALLBACK CXShell::BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
- {
- TCHAR szDir[MAX_PATH];
- switch(uMsg){
- case BFFM_INITIALIZED:
- if (lpData)
- {
- strcpy(szDir, strTmpPath.GetBuffer(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;
- }
- return 0;
- }
- //@1
- BOOL CXShell::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 = BrowseCallbackProc;
- 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);
- return TRUE;
- }
- }else{
- strSelectedFolder->Empty();
- }
- return FALSE;
- }
- //////////////////////////////////////////////////////////////////////////
- void CXShell::ShowFileProperties(const char *lpszFilename)
- {
- //open the file property window.
-
- SHELLEXECUTEINFO sei;
- sei.cbSize = sizeof(sei);
- sei.hwnd = NULL;
- sei.lpDirectory = NULL;
- sei.lpParameters = NULL;
- sei.hInstApp = NULL;
- sei.lpIDList = NULL;
- sei.hProcess = NULL;
- sei.nShow = SW_SHOW;
- sei.lpVerb = "properties";
- sei.lpFile = lpszFilename;
- sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_INVOKEIDLIST | SEE_MASK_FLAG_NO_UI | SEE_MASK_ASYNCOK;
-
- ShellExecuteEx(&sei);
- }