Exemplo n.º 1
1
void CXMLDialog::GetPath(CString& strPath, CString strTitle)
{
	LPITEMIDLIST lpItemList = NULL;
	LPSHELLFOLDER pDesktopFolder;
	if (!strPath.IsEmpty())
	{
		OLECHAR chOlePath[255];
		ULONG   pchEaten;
		ULONG   dwAttributes;

		HRESULT hr = SHGetDesktopFolder(&pDesktopFolder);
		MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, strPath.GetBuffer(MAX_PATH), -1,
	                         chOlePath, MAX_PATH);
		strPath.ReleaseBuffer (-1);

		hr = pDesktopFolder->ParseDisplayName(NULL,
                                            NULL,
                                            chOlePath,
                                            &pchEaten,
                                            &lpItemList,
                                            &dwAttributes);
	}

	BROWSEINFO binfo;
	binfo.hwndOwner = NULL;
	binfo.pidlRoot = lpItemList; //NULL;
	binfo.pszDisplayName = NULL;
	binfo.lpszTitle = (LPCTSTR)strTitle;
	binfo.ulFlags = BIF_RETURNONLYFSDIRS|BIF_RETURNFSANCESTORS|BIF_NONEWFOLDERBUTTON;
	binfo.lpfn = NULL;
	binfo.lParam = 0;
	binfo.iImage = 0;

	LPITEMIDLIST pItemID = SHBrowseForFolder(&binfo);	
	if (!pItemID)
		return;

	TCHAR szPath[MAX_PATH];
	*szPath = _T('\0');
	SHGetPathFromIDList(pItemID, szPath);
	strPath = szPath;
}
Exemplo n.º 2
0
// Convert a char* into a LPITEMIDLIST
LPITEMIDLIST XSHBFF_PathConvert(HWND hwnd,char* _path) {
  // Retrieves the IShellFolder interface for the desktop folder
  LPSHELLFOLDER MyShellFolder;
  if (SHGetDesktopFolder(&MyShellFolder) != NO_ERROR)
    return NULL;
  
  // Initial path
  ULONG pchEaten;
  LPITEMIDLIST MyItemlist=NULL;
  ULONG pdwAttributes;
  if (strlen(_path)>0) {
    char* lpszA = _path;
    // -- Unicode conversion--
    // we want to convert an MBCS string into lpszA    
    int nLen = MultiByteToWideChar(CP_ACP, 0,lpszA, -1, NULL, NULL);
    LPWSTR lpszW = new WCHAR[nLen];
    MultiByteToWideChar(CP_ACP, 0, lpszA, -1, lpszW, nLen);
    // parse string
    MyShellFolder->ParseDisplayName(hwnd,NULL,lpszW,&pchEaten,&MyItemlist,&pdwAttributes);
    // free the string
    delete[] lpszW;
    // -- Unicode conversion--    
  }
  return MyItemlist;
}
Exemplo n.º 3
0
BOOL CRecBinViewer::GetFolder2 ()
{
	BOOL			bReturn			= FALSE;
	STRRET			strRet;
	LPSHELLFOLDER	pDesktop		= NULL;
	LPITEMIDLIST	pidlRecycleBin	= NULL;
	CString			dspName;

	
	if (NULL != m_pFolder2)
	{
		m_pFolder2->Release ();
		m_pFolder2 = NULL;
	}
	
	if ((SUCCEEDED (SHGetDesktopFolder(&pDesktop))) &&
		(SUCCEEDED (SHGetSpecialFolderLocation (m_hWnd, CSIDL_BITBUCKET, &pidlRecycleBin))))
	{
		if (SUCCEEDED (pDesktop->BindToObject(pidlRecycleBin, NULL, IID_IShellFolder2, (LPVOID *)&m_pFolder2)))
		{
			if (S_OK == pDesktop->GetDisplayNameOf (pidlRecycleBin, SHGDN_NORMAL, &strRet))			
				GetName (strRet, dspName);			
			bReturn = TRUE;
		}
	}
		
	CoTaskMemFree (pidlRecycleBin);
	
	if (NULL != pDesktop) pDesktop->Release();
	
	return bReturn;
}
Exemplo n.º 4
0
LPITEMIDLIST GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi)
{
   char szBuff[MAX_PATH];
   OLECHAR szOleChar[MAX_PATH];
   LPSHELLFOLDER lpsfDeskTop;
   LPITEMIDLIST  lpifq;
   ULONG ulEaten, ulAttribs;
   HRESULT hr;

   if( !GetName(lpsf, lpi, SHGDN_FORPARSING, szBuff))
      return NULL;

   hr=SHGetDesktopFolder(&lpsfDeskTop) ;

   if( FAILED(hr))
      return NULL;

   MultiByteToWideChar(CP_ACP,
					   MB_PRECOMPOSED,
					   szBuff,
					   -1,
					   szOleChar,
					   sizeof(szOleChar)) ;

   hr=lpsfDeskTop->ParseDisplayName(NULL,NULL,szOleChar,&ulEaten,&lpifq,&ulAttribs) ;

   lpsfDeskTop->Release() ;

   if( FAILED(hr))
      return NULL;

   return lpifq;
}
Exemplo n.º 5
0
//***************************************************************************************
HRESULT CBCGPShellList::DisplayFolder (LPCTSTR lpszPath)
{
	if (g_pShellManager == NULL)
	{
		ASSERT (FALSE);
		return E_FAIL;
	}

	ASSERT (lpszPath != NULL);
	ASSERT_VALID (g_pShellManager);

	BCGCBITEMINFO info;
	HRESULT hr = g_pShellManager->ItemFromPath (lpszPath, info.pidlRel);

	if (FAILED (hr))
	{
		return hr;
	}

	LPSHELLFOLDER pDesktopFolder;
	hr = SHGetDesktopFolder(&pDesktopFolder);

	if (SUCCEEDED (hr))
	{
		info.pParentFolder = pDesktopFolder;
		info.pidlFQ = info.pidlRel;

		hr = DisplayFolder (&info);
		pDesktopFolder->Release();
	}

	g_pShellManager->FreeItem (info.pidlFQ);
	return hr;
}
Exemplo n.º 6
0
//Pabs inserted
//Parts copied from compiler docs - search for ITEMIDLIST in title in msdn
//Adapted from Q132750:"HOWTO: Convert a File Path to an ITEMIDLIST" in the Knowledge Base
STDAPI PathsEqual(LPCTSTR p0, LPCTSTR p1)
{
	LPSHELLFOLDER pFolder;
	HRESULT hr;
	if (SUCCEEDED(hr = SHGetDesktopFolder(&pFolder)))
	{
		LPITEMIDLIST pidl[2] = { NULL, NULL };
		ULONG chEaten;//only needed by parse dispname
		// Convert the paths to ITEMIDLISTs.
		if (SUCCEEDED(hr = pFolder->ParseDisplayName(NULL, NULL,
				const_cast<LPOLESTR>(&*static_cast<T2W>(p0)), &chEaten, &pidl[0], NULL)) &&
			SUCCEEDED(hr = pFolder->ParseDisplayName(NULL, NULL,
				const_cast<LPOLESTR>(&*static_cast<T2W>(p1)), &chEaten, &pidl[1], NULL)))
		{
			hr = pFolder->CompareIDs(0, pidl[0], pidl[1]);
		}

		//free ITEMIDLISTs
		IMalloc* pm;
		SHGetMalloc(&pm);
		pm->Free(pidl[0]);
		pm->Free(pidl[1]);
		pm->Release();

		pFolder->Release();
	}
	return hr;
}
Exemplo n.º 7
0
/*
 * Get a fully qualified PIDL for a ShellFolder.
 *
 * This is a rather roundabout way of doing things (converting to a full
 * display name and then converting that to a PIDL).  However, there doesn't
 * seem to be a way to just ask a ShellFolder for its fully qualified PIDL.
 * TODO: see if there's a better way now.
 *
 * Pass in the parent ShellFolder and the item's partial PIDL.
 */
LPITEMIDLIST
Pidl::GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi)
{
    //char szBuff[MAX_PATH];
    //OLECHAR szOleChar[MAX_PATH];
    CString name;
    WCHAR pathBuf[MAX_PATH];
    LPSHELLFOLDER lpsfDeskTop;
    LPITEMIDLIST lpifq;
    ULONG ulAttribs = 0;
    HRESULT hr;
    
    if (!GetName(lpsf, lpi, SHGDN_FORPARSING, &name))
        return NULL;
    
    hr = SHGetDesktopFolder(&lpsfDeskTop);
    
    if (FAILED(hr))
        return NULL;
    
    //MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szBuff, -1,
    //                   (USHORT *)szOleChar, sizeof(szOleChar));
    wcscpy_s(pathBuf, name);
    
    hr = lpsfDeskTop->ParseDisplayName(NULL, NULL, pathBuf,
            NULL, &lpifq, &ulAttribs);
    
    lpsfDeskTop->Release();
    
    if (FAILED(hr))
        return NULL;
    
    return lpifq;
}
Exemplo n.º 8
0
ITEMIDLIST* CUtil::IDListFromPath(LPCTSTR pathName)
{
  LPSHELLFOLDER   pDesktopFolder;
  HRESULT         hr = SHGetDesktopFolder(&pDesktopFolder);
  ITEMIDLIST*     pidl=NULL;

  if (FAILED(hr)) {
    assert(0); 
    return NULL;
  }

  OLECHAR olePath [MAX_PATH];

#ifdef _UNICODE
  lstrcpy(olePath, pathName);
#else
  MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszPath, -1, pathName, MAX_PATH);
#endif

  ULONG chEaten;
  ULONG dwAttributes;
  hr = pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, &pidl, &dwAttributes);

  pDesktopFolder->Release();
  return pidl;
}
Exemplo n.º 9
0
BOOL sh_get_displayname(LPSHELLFOLDER piFolder, LPCITEMIDLIST pidl,
						 DWORD dwFlags, LPTSTR pszName)
{
	STRRET str;
	BOOL fDesktop = FALSE;
	BOOL fSuccess = TRUE;
	//
	// Check to see if a parent folder was specified.  If not, get a pointer
	// to the desktop folder.
	//
	if (NULL == piFolder)   
	{
		HRESULT hr = SHGetDesktopFolder(&piFolder);

		if (FAILED(hr))
			return (FALSE);

		fDesktop = TRUE;
	}
	//
	// Get the display name from the folder.  Then do any conversions necessary
	// depending on the type of string returned.
	//
	if (NOERROR == piFolder->GetDisplayNameOf(pidl, dwFlags, &str))
	{
		//StrRetToBufA(&str, pidl, pszName, MAX_PATH);
		switch (str.uType)
		{
			case STRRET_WSTR:
				WideCharToMultiByte(CP_ACP, 0, str.pOleStr, -1, pszName, MAX_PATH, NULL, NULL);
				SHMalloc_Free(str.pOleStr);
				//dbg_printf("WSTR: %s", pszName);
				break;

			case STRRET_OFFSET:
				strcpy(pszName, (LPSTR)pidl + str.uOffset);
				//dbg_printf("OFFS: %s", pszName);
				break;

			case STRRET_CSTR:
				strcpy(pszName, str.cStr);
				//dbg_printf("CSTR: %s", pszName);
				break;

			default:
				fSuccess = FALSE;
				break;
		}
	}
	else
	{
		fSuccess = FALSE;
	}

	if (fDesktop)
		piFolder->Release();

	return (fSuccess);
}
Exemplo n.º 10
0
/**
 * 简单的枚举文件夹内容,返回内容数量
 */
int SimpleEnumFolder(LPCTSTR lpszPath		// 文件夹路径
	, CShellManager* pShellManager			// Shell管理器
	, function<void(LPITEMIDLIST)> filter)	// 过滤器函数
{
	ENSURE(lpszPath != nullptr);
	ASSERT_VALID(pShellManager);

	AFX_SHELLITEMINFO info;
	HRESULT hr = pShellManager->ItemFromPath(lpszPath, info.pidlRel);
	if (FAILED(hr))	{
		return 0;
	}

	int nFolderCount = 0;

	LPSHELLFOLDER pDesktopFolder;
	hr = SHGetDesktopFolder(&pDesktopFolder);

	if (SUCCEEDED(hr)) {

		IShellFolder* psfCurFolder = nullptr;
		hr = pDesktopFolder->BindToObject(info.pidlRel, nullptr, IID_IShellFolder, (LPVOID*)&psfCurFolder);

		LPENUMIDLIST pEnum = nullptr;
		HRESULT hRes = psfCurFolder->EnumObjects(nullptr, (SHCONTF)(SHCONTF_FOLDERS), &pEnum);
		if (SUCCEEDED(hRes) && pEnum != nullptr) {

			DWORD dwFetched = 1;
			LPITEMIDLIST pidlTemp;
			while (pEnum->Next(1, &pidlTemp, &dwFetched) == S_OK && dwFetched) {

				if (!filter._Empty()) {
					LPITEMIDLIST itemID = pShellManager->ConcatenateItem(info.pidlRel, pidlTemp);
					filter(itemID);
					pShellManager->FreeItem(itemID);
				}

				pShellManager->FreeItem(pidlTemp);

				nFolderCount++;
				dwFetched = 0;
			}

			pEnum->Release();
		}

		psfCurFolder->Release();
		pDesktopFolder->Release();
	}

	pShellManager->FreeItem(info.pidlRel);
	return nFolderCount;
}
bool CXTPShellListCtrlEx::BrowseToFolder(LPCTSTR lpszPath)
{
	XTP_TVITEMDATA lpTVID;

	LPITEMIDLIST  pidl;
	LPSHELLFOLDER pDesktopFolder;
	OLECHAR       szOleChar[MAX_PATH];
	ULONG         chEaten;
	ULONG         dwAttributes;
	HRESULT       hr;

	// Get a pointer to the Desktop's IShellFolder interface.
	if (SUCCEEDED(::SHGetDesktopFolder(&pDesktopFolder)))
	{
		// IShellFolder::ParseDisplayName requires the file name be in
		// Unicode.

#if !defined(_UNICODE)
		::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszPath, -1,
			szOleChar, MAX_PATH);
#else
		STRCPY_S(szOleChar, MAX_PATH, lpszPath);
#endif

		// Convert the path to an ITEMIDLIST.
		hr = pDesktopFolder->ParseDisplayName(NULL, NULL, szOleChar,
			&chEaten, &pidl, &dwAttributes);

		if (SUCCEEDED(hr))
		{
			IShellFolder *psfMyFolder;

			lpTVID.lpi = lpTVID.lpifq = pidl;

			pDesktopFolder->BindToObject(lpTVID.lpifq, NULL,
				IID_IShellFolder, (LPVOID*)&psfMyFolder);

			lpTVID.lpsfParent = psfMyFolder;
			PopulateListView(&lpTVID, lpTVID.lpsfParent);

			m_strItemPath = lpszPath;
			pDesktopFolder->Release();

			return true;
		}

		pDesktopFolder->Release();
	}

	return false;
}
Exemplo n.º 12
0
//This gets a fully qualified long absolute filename from any other type of file name ON ANY Win32 PLATFORM damn stupid Micro$uck$ & bloody GetLongPathName
//It was copied and enhanced from an article by Jeffrey Richter available in the MSDN under "Periodicals\Periodicals 1997\Microsoft Systems Journal\May\Win32 Q & A" (search for GetLongPathName & choose the last entry)
STDAPI GetLongPathNameWin32(LPCTSTR lpszShortPath, LPTSTR lpszLongPath)
{
	/*Alternative methods to consider adding here
	GetLongPathName on Win98/NT5
	Recursive FindFirstFile ... FindClose calls
	Interrupt 21h Function 7160h Minor Code 2h
	- does exactly what we want
		- to the damn letter
		- even resolves SUBST's (or not if you only want the drive letter)
			- remember those from DOS?
	- but the MSDN doesn't say anything about whether or not it is supported
	  by WinNT4 (It is only listed in Win95 docs)*/

	// Do not attempt to operate in-place
	if (lpszLongPath == lpszShortPath)
		return S_FALSE;
	// Make sure it is an absolute path
	LPTSTR lpszFilePart = 0;
	if (GetFullPathName(lpszShortPath, MAX_PATH, lpszLongPath, &lpszFilePart) <= MAX_PATH)
	{
		// Get the Desktop's shell folder interface
		LPSHELLFOLDER psfDesktop = 0;
		HRESULT hr = SHGetDesktopFolder(&psfDesktop);
		if (SUCCEEDED(hr))
		{
			// Request an ID list (relative to the desktop) for the short pathname
			ULONG chEaten = 0;
			LPITEMIDLIST pidlShellItem = 0;
			hr = psfDesktop->ParseDisplayName(0, 0, const_cast<LPWSTR>(&*static_cast<T2W>(lpszLongPath)), &chEaten, &pidlShellItem, 0);
			if (SUCCEEDED(hr))
			{
				// We did get an ID list, convert it to a long pathname
				SHGetPathFromIDList(pidlShellItem, lpszLongPath);
				// Free the ID list allocated by ParseDisplayName
				LPMALLOC pMalloc = NULL;
				SHGetMalloc(&pMalloc);
				pMalloc->Free(pidlShellItem);
				pMalloc->Release();
			}
			psfDesktop->Release(); // Release the desktop's IShellFolder
		}
	}
	else
	{
		lstrcpy(lpszLongPath, lpszShortPath);
	}
	return S_OK;
}
Exemplo n.º 13
0
BOOL CShellMgr::GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, DWORD dwFlags, LPTSTR lpFriendlyName)
{
	BOOL bSuccess = TRUE;
	STRRET str = { STRRET_CSTR };

	if (lpsf->GetDisplayNameOf(lpi, dwFlags, &str) == NOERROR)
	{
		USES_CONVERSION;

		switch (str.uType)
		{
		case STRRET_WSTR:
			lstrcpy(lpFriendlyName, W2CT(str.pOleStr));
			::CoTaskMemFree(str.pOleStr);
			break;
		case STRRET_OFFSET:
			lstrcpy(lpFriendlyName, (LPTSTR)lpi + str.uOffset);
			break;
		case STRRET_CSTR:
			lstrcpy(lpFriendlyName, A2CT(str.cStr));
			break;
		default:
			bSuccess = FALSE;
			break;
		}
	}
	else
	{
		bSuccess = FALSE;
	}

	return bSuccess;
}
Exemplo n.º 14
0
// parent IShellFolder, simple PIDL -> IShellFolder
xpr_bool_t Pidl::getShellFolder(LPSHELLFOLDER aParentShellFolder, LPCITEMIDLIST aPidl, LPSHELLFOLDER &aShellFolder)
{
    XPR_ASSERT(aParentShellFolder != XPR_NULL);
    XPR_ASSERT(aPidl != XPR_NULL);

    HRESULT sComResult;

    sComResult = aParentShellFolder->BindToObject(
        (LPCITEMIDLIST)aPidl,
        0,
        IID_IShellFolder,
        reinterpret_cast<LPVOID *>(&aShellFolder));

    if (FAILED(sComResult) || XPR_IS_NULL(aShellFolder))
    {
        sComResult = ::SHGetDesktopFolder(&aShellFolder); // desktop PIDL is null.

        if (FAILED(sComResult))
        {
            return XPR_FALSE;
        }
    }

    return XPR_TRUE;
}
Exemplo n.º 15
0
void CSelectDrivesDlg::OnBnClickedBrowsefolder()
{
	// Buffer, because SHBrowseForFolder() wants a buffer
	CString sDisplayName, sSelectedFolder = m_folderName;
	BROWSEINFO bi;
	ZeroMemory(&bi, sizeof(bi));

	// Load a meaningful title for the browse dialog
	CString title= LoadString(IDS_SELECTFOLDER);
	bi.hwndOwner= m_hWnd;
	// Use the CString as buffer (minimum is MAX_PATH as length)
	bi.pszDisplayName= sDisplayName.GetBuffer(_MAX_PATH);
	bi.lpszTitle= title;
	// Set a callback function to pre-select a folder
	bi.lpfn = BFFCALLBACK(BrowseCallbackProc);
	bi.lParam = LPARAM(sSelectedFolder.GetBuffer());
	// Set the required flags
	bi.ulFlags= BIF_RETURNONLYFSDIRS | BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_NONEWFOLDERBUTTON;
	
	LPITEMIDLIST pidl= SHBrowseForFolder(&bi);
	// Release the actual buffer
	sDisplayName.ReleaseBuffer();
	sSelectedFolder.ReleaseBuffer();

	if (pidl != NULL)
	{
		CString sDir;

		LPSHELLFOLDER pshf;
		HRESULT hr= SHGetDesktopFolder(&pshf); 
		ASSERT(SUCCEEDED(hr));
		
		STRRET strret;
		strret.uType= STRRET_CSTR;
		hr= pshf->GetDisplayNameOf(pidl, SHGDN_FORPARSING, &strret);
		ASSERT(SUCCEEDED(hr));
		sDir= MyStrRetToString(pidl, &strret);

		CoTaskMemFree(pidl);
		pshf->Release();

		m_folderName= sDir;
		m_radio= RADIO_AFOLDER;
		UpdateData(false);
		UpdateButtons();
	}
}
Exemplo n.º 16
0
        Ztring OpenFolder_Show(void* Handle, const Ztring &Title, const Ztring &Caption)
        {
            //Caption
            Directory_Select_Caption=Caption;

            if (IsWin9X())
            {
                return Ztring(); //Not supported in Win9X
            }
            else
            {
                //Values
                LPMALLOC        Malloc;
                LPSHELLFOLDER   ShellFolder;
                BROWSEINFO      BrowseInfo;
                LPITEMIDLIST    ItemIdList;

                //Initializing the SHBrowseForFolder function
                if (SHGetMalloc(&Malloc)!=NOERROR)
                    return Ztring();
                if (SHGetDesktopFolder(&ShellFolder)!=NOERROR)
                    return Ztring();
                ZeroMemory(&BrowseInfo, sizeof(BROWSEINFOW));
                BrowseInfo.ulFlags+=BIF_RETURNONLYFSDIRS;
                BrowseInfo.hwndOwner=(HWND)Handle;
                BrowseInfo.pszDisplayName=InitDir;
                BrowseInfo.lpszTitle=Title.c_str();
                BrowseInfo.lpfn=ShowOpenFolder_CallbackProc;

                //Displaying
                ItemIdList=SHBrowseForFolder(&BrowseInfo);

                //Releasing
                ShellFolder->Release();
                if (ItemIdList!=NULL)
                {
                    SHGetPathFromIDList(ItemIdList, InitDir);
                    Malloc->Free(ItemIdList);
                    Malloc->Release();

                    //The value
                    return InitDir;
                }
                else
                    return Ztring();
            }
        }
BOOL COXShellNamespaceNavigator::
GetShellFolderFullIDL(CString sFolderFullPath,
					  LPITEMIDLIST* ppidlFull) const
{
	ASSERT(ppidlFull!=NULL);

	// If lpcsFolderFullPath is NULL then just return the Desktop's IDL which is NULL
	if(sFolderFullPath.IsEmpty())
	{
		*ppidlFull=NULL;
		return TRUE;
	}

	// First of all get the Desktop's IShellFolder interface. 
	LPSHELLFOLDER lpDesktopFolder;
    if(FAILED(SHGetDesktopFolder(&lpDesktopFolder)))
        return FALSE;


	OLECHAR unicodeFolderPath[MAX_PATH];

#ifndef _UNICODE
	UTBStr::mbstowcs(unicodeFolderPath,MAX_PATH,sFolderFullPath,MAX_PATH);
#else
	UTBStr::tcscpy(unicodeFolderPath, MAX_PATH, sFolderFullPath);
#endif

	LPITEMIDLIST lpidl;
    ULONG chEaten;
    ULONG dwAttributes;
    HRESULT hResult=lpDesktopFolder->
		ParseDisplayName(m_pOwnerWnd!=NULL ? m_pOwnerWnd->GetSafeHwnd() : NULL,
		NULL,unicodeFolderPath,&chEaten,&lpidl,&dwAttributes);
	if(FAILED(hResult))
	{
		lpDesktopFolder->Release();
		m_pMalloc->Free(lpidl);
        return FALSE;
	}

	*ppidlFull=CopyPIDL(lpidl);
	lpDesktopFolder->Release();
	m_pMalloc->Free(lpidl);

	return TRUE;
}
Exemplo n.º 18
0
HRESULT WINAPI _SHILCreateFromPath(LPCWSTR pszPath, LPITEMIDLIST *ppidl, DWORD *rgflnOut)
{
   if (!pszPath || !ppidl) {
      return E_INVALIDARG;
   }

   LPSHELLFOLDER psf;
   HRESULT hr = ::SHGetDesktopFolder(&psf);
   if (hr != NOERROR) {
      return hr;
   }

   ULONG chEaten;
   LPOLESTR lpszDisplayName = ::StrDupW(pszPath);
   hr = psf->ParseDisplayName(NULL, NULL, lpszDisplayName, &chEaten, ppidl, rgflnOut);
   ::LocalFree(lpszDisplayName);
   psf->Release();
   return hr;
}
Exemplo n.º 19
0
LPITEMIDLIST ConvertPathToLpItemIdList(const TCHAR* pszPath)
{
  LPITEMIDLIST  pidl = NULL;
  LPSHELLFOLDER pDesktopFolder;

  if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
  {
    OLECHAR       olePath[MAX_PATH];
    ULONG         chEaten;
    ULONG         dwAttributes;
    HRESULT       hr;

    _tcscpy_s(olePath, pszPath);
    hr = pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, 
      &chEaten, &pidl, &dwAttributes);
    pDesktopFolder->Release();
  }

  return pidl;
}
Exemplo n.º 20
0
xpr_bool_t Pidl::getAttributes(LPSHELLFOLDER aShellFolder, LPCITEMIDLIST aPidl, xpr_ulong_t &aAttributes)
{
    HRESULT sComResult = aShellFolder->GetAttributesOf(1, (LPCITEMIDLIST *)&aPidl, &aAttributes);
    if (FAILED(sComResult))
    {
        return XPR_FALSE;
    }

    filterAttributes(aShellFolder, aPidl, aAttributes);

    return XPR_TRUE;
}
Exemplo n.º 21
0
//***************************************************************************************
HRESULT CBCGPShellList::DisplayParentFolder ()
{
	ASSERT_VALID (g_pShellManager);

	HRESULT hr = E_FAIL;
	if (m_pidlCurFQ == NULL)
	{
		return hr;
	}

	BCGCBITEMINFO info;
	int nLevel = g_pShellManager->GetParentItem (m_pidlCurFQ, info.pidlFQ);

	if (nLevel < 0)
	{
		return hr;
	}

	if (nLevel == 0)	// Desktop
	{
		hr = DisplayFolder (&info);
	}
	else
	{
		LPSHELLFOLDER pDesktopFolder;
		hr = SHGetDesktopFolder(&pDesktopFolder);

		if (SUCCEEDED (hr))
		{
			info.pParentFolder = pDesktopFolder;
			info.pidlRel = info.pidlFQ;

			hr = DisplayFolder (&info);
			pDesktopFolder->Release();
		}
	}

	g_pShellManager->FreeItem (info.pidlFQ);
	return hr;
}
Exemplo n.º 22
0
BOOL BrowseForFolder(HWND hWnd, CString& strTitle, CString& strResult, BOOL bIncludeFiles, _tBrowseCallbackProc pCallback)
{
	BOOL bRet = FALSE;
    WCHAR szFolder[MAX_PATH * 2];
	
	ZeroMemory(szFolder, sizeof(szFolder));
	
    BROWSEINFO info;
    LPSHELLFOLDER shell;
    LPITEMIDLIST FolderID;
	
    SHGetDesktopFolder(&shell);
	
    info.hwndOwner = hWnd;
    info.pidlRoot = NULL;
    info.pszDisplayName = szFolder;
    info.lpszTitle = strTitle.GetBuffer(MAX_PATH);
    info.ulFlags = BIF_NEWDIALOGSTYLE;
	if (bIncludeFiles)
		info.ulFlags |= BIF_BROWSEINCLUDEFILES | BIF_NONEWFOLDERBUTTON;
    info.lpfn = pCallback;
	
    FolderID = SHBrowseForFolder(&info);
	
	if(FolderID != NULL)
	{
		if(SHGetPathFromIDList(FolderID, szFolder))
		{
			strResult= szFolder;
			bRet = TRUE;
		}
	}
	
    shell->Release();

	strTitle.ReleaseBuffer();
	
	return bRet;
}
void CBrowseForFolder::GetPidl(CString name, LPITEMIDLIST pidl)
{
	LPSHELLFOLDER pshf;
	ULONG chEaten;
	
#ifdef _UNICODE
	OLECHAR* oleRoot = name.GetBuffer(name.GetLength());
#else
	OLECHAR oleRoot[MAX_PATH];
	// convert path to Unicode string
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1,
		oleRoot, MAX_PATH);
#endif	
	if (SUCCEEDED(SHGetDesktopFolder(&pshf)))
	{
		// get pidl
		pshf->ParseDisplayName(hWndOwner, NULL, oleRoot, &chEaten, 
			&pidl, NULL);
	}
	else return;
	pshf->Release();
}
Exemplo n.º 24
0
// first called when the mouse enters our target window space
STDMETHODIMP CDropTarget::DragEnter(LPDATAOBJECT pDataObject, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
{
    // don't set "*pdwEffect = DROPEFFECT_NONE"; that would adversely affect the drop target
    BOOL ok = FALSE;
    AddRef();
    if (m_pidl)
    {
        LPSHELLFOLDER psfFolder;
        LPITEMIDLIST pidlItem;
        LPITEMIDLIST pidlFull;
        if (sh_get_uiobject(m_pidl, &pidlFull, &pidlItem, &psfFolder, IID_IDropTarget, (void**)&m_pDropTarget))
        {
            HRESULT hr = m_pDropTarget->DragEnter(pDataObject, grfKeyState, pt, pdwEffect);
            if(SUCCEEDED(hr)) ok = TRUE;
        }
        if (psfFolder) psfFolder->Release();
        freeIDList(pidlItem);
        freeIDList(pidlFull);
    }
    if(FALSE == ok) *pdwEffect = DROPEFFECT_NONE; // we can't understand this thing
    m_pDataObject = pDataObject;
    return S_OK;
}
Exemplo n.º 25
0
LPITEMIDLIST getAbsolutePidlFromAbsFilePath(LPWSTR path)
{
	LPITEMIDLIST pidl = NULL;
	LPITEMIDLIST pidlAbsolute = NULL;

	// namespace extension root (desktop) for parsing path
	LPSHELLFOLDER psfDesktop = NULL;
	if (FAILED(SHGetDesktopFolder(&psfDesktop)))
		return pidl;

	// parse path for absolute PIDL
	if (FAILED(psfDesktop->ParseDisplayName(NULL, NULL, path, NULL, &pidl, NULL)))
		return pidl;

	// get the absolute pidl, do not need to free pidlTemp
	pidlAbsolute = ILClone(pidl);

	// cleanup
	CoTaskMemFree(pidl);
	psfDesktop->Release();

	return pidlAbsolute;
}
Exemplo n.º 26
0
xpr_ulong_t Pidl::getAttributes(LPSHELLFOLDER aShellFolder, LPCITEMIDLIST aPidl)
{
    xpr_ulong_t sAttributes = SFGAO_CAPABILITYMASK | SFGAO_DISPLAYATTRMASK | SFGAO_CONTENTSMASK | 0x7F300000;

    HRESULT sComResult = aShellFolder->GetAttributesOf(1, (LPCITEMIDLIST *)&aPidl, &sAttributes);
    if (FAILED(sComResult))
    {
        return 0;
    }

    filterAttributes(aShellFolder, aPidl, sAttributes);

    return sAttributes;
}
Exemplo n.º 27
0
// Get long path name from short path name.
// assumes that LongPath has enough characters to hold the generated name
static bool ShortPathToLongPath (const char *ShortPath, char *LongPath)
{
// Man, this is a seriously disturbed function.
// Win32 could use a GetLongFileName function (NT 5 has one...)
	LPSHELLFOLDER psfDesktop = NULL;

	WCHAR szShortPathNameW[MAX_PATH];

	// convert path name to wide and copy to local storage
	ULONG chEaten = 0;
	LPITEMIDLIST pidlShellItem = NULL;

	mbstowcs (szShortPathNameW, ShortPath, MAX_PATH);

	// Get desktop's shell folder interface
	HRESULT hr = SHGetDesktopFolder (&psfDesktop);

	// request an ID list (relative to the desktop) for the short pathname
	hr = psfDesktop->ParseDisplayName (NULL, NULL, szShortPathNameW, &chEaten, &pidlShellItem, NULL);
	psfDesktop->Release ();		// release desktop's IShellFolder

	if (FAILED (hr))
	{
		return false;
	}

	// got an ID list.  Convert it to a long pathname
	SHGetPathFromIDListA (pidlShellItem, LongPath);

	// Free the ID list allocated by ParseDisplayName
	LPMALLOC pMalloc = NULL;
	SHGetMalloc (&pMalloc);
	pMalloc->Free (pidlShellItem);
	pMalloc->Release ();

	return true;
}
Exemplo n.º 28
0
//初始化浏览器控件(nID为资源文件中树型控件的id)
BOOL Init_Browser(HWND hWnd,UINT nID)
{
	HIMAGELIST hImageList;
   LPSHELLFOLDER lpsf = 0 ;
   SHFILEINFO    sfi;
	HRESULT hr ;
	BOOL bOK;

	memset(szFoldername,0,MAX_PATH);
   hTreeWnd=GetDlgItem(hWnd,nID);

   hImageList = (HIMAGELIST)SHGetFileInfo((LPCSTR)"C:\\",
                                           0,
                                           &sfi,
                                           sizeof(SHFILEINFO),
                                           SHGFI_SYSICONINDEX | SHGFI_SMALLICON) ;

  	if(hImageList)
   	TreeView_SetImageList(hTreeWnd,hImageList,0);

	hr=SHGetDesktopFolder(&lpsf) ;

	if( SUCCEEDED(hr))
	{
	   TreeView_DeleteAllItems(hTreeWnd);
	   FillTreeView(hTreeWnd,lpsf,NULL,TVI_ROOT) ;
      ExpandTree();
      TreeView_SelectItem(hTreeWnd,TreeView_GetRoot(hTreeWnd));//,TVGN_FIRSTVISIBLE);
      bOK = TRUE;
	}
   else
   	bOK = FALSE;

	if(lpsf)
		lpsf->Release();
	return bOK;
}
Exemplo n.º 29
0
/* #FN#
   Populates the tree view control with file list */
void
/* #AS#
   Nothing */
CShellTree::
PopulateTree()
{
	LPSHELLFOLDER lpsf = NULL;
	LPITEMIDLIST  lpi  = NULL;
	HRESULT hr;

	/* Get a pointer to the desktop folder */
	hr = SHGetDesktopFolder( &lpsf );

	if( SUCCEEDED(hr) )
	{
		/* Initialize the tree view to be empty */
		DeleteAllItems();

		/* Fill in the tree view from the root */
		FillTreeView( lpsf, NULL, TVI_ROOT );
		/* Release the folder pointer */
		lpsf->Release();
	}
	TV_SORTCB tvscb;
	tvscb.hParent     = TVI_ROOT;
	tvscb.lParam      = 0;
	tvscb.lpfnCompare = TreeViewCompareProc;

	/* Sort the items in the tree view */
	SortChildrenCB( &tvscb /*, FALSE*/ );

	HTREEITEM hItem = GetRootItem();
	Expand( hItem, TVE_EXPAND );
	Select( GetRootItem(), TVGN_CARET );

} /* #OF# CShellTree::PopulateTree */
Exemplo n.º 30
0
/*
 * Get the display name of a file in a ShellFolder.
 *
 * "lpsf" is the ShellFolder that contains the file, "lpi" is the PIDL for
 * the file, "dwFlags" is passed to GetDisplayNameOf and affects which
 * name is returned, and "lpFriendlyName" is a buffer of at least MAX_PATH
 * bytes.
 */
BOOL
Pidl::GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, DWORD dwFlags,
    CString* pFriendlyName)
{
    BOOL   bSuccess=TRUE;
    STRRET str;

    if (NOERROR == lpsf->GetDisplayNameOf(lpi, dwFlags, &str)) {
        switch (str.uType) {
        case STRRET_WSTR:
            //WideCharToMultiByte(CP_ACP,             // CodePage
            //                    0,                  // dwFlags
            //                    str.pOleStr,        // lpWideCharStr
            //                    -1,                 // cchWideChar
            //                    lpFriendlyName,     // lpMultiByteStr
            //                    MAX_PATH,           // cchMultiByte
            //                    NULL,               // lpDefaultChar,
            //                    NULL);              // lpUsedDefaultChar

            ////Once the the function returns, the wide string
            ////should be freed. CoTaskMemFree(str.pOleStr) seems
            ////to do the job as well.
            //LPMALLOC pMalloc;
            //SHGetMalloc(&pMalloc); 
            //pMalloc->Free (str.pOleStr);
            //pMalloc->Release();
            *pFriendlyName = str.pOleStr;
            CoTaskMemFree(str.pOleStr);
            break;

         case STRRET_OFFSET:
             *pFriendlyName = (LPSTR)lpi+str.uOffset;
             break;

         case STRRET_CSTR:
             *pFriendlyName = (LPSTR)str.cStr;
             break;

         default:
             bSuccess = FALSE;
             break;
        }
    } else {
        bSuccess = FALSE;
    }

    return bSuccess;
}