Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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;
}
Exemplo n.º 5
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.º 6
0
/****************************************************************************
*
*    FUNCTION: GetName(LPSHELLFOLDER lpsf,LPITEMIDLIST  lpi,DWORD dwFlags,
*             LPSTR         lpFriendlyName)
*
*    PURPOSE:  Gets the friendly name for the folder
*
****************************************************************************/
BOOL CShellPidl::GetName(LPSHELLFOLDER lpsf,
                         LPITEMIDLIST  lpi,
                         DWORD         dwFlags,
                         LPSTR         lpFriendlyName)
{
    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,
                                //sizeof(lpFriendlyName), // cchMultiByte, wrong. sizeof on a pointer, psk, psk
                                NULL,                   // lpDefaultChar,
                                NULL);                  // lpUsedDefaultChar

            break;

        case STRRET_OFFSET:

            lstrcpy(lpFriendlyName, (LPSTR)lpi+str.uOffset);
            break;

        case STRRET_CSTR:

            lstrcpy(lpFriendlyName, (LPSTR)str.cStr);
            break;

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

    return bSuccess;
}
Exemplo n.º 7
0
xpr_bool_t Pidl::getName(LPSHELLFOLDER aShellFolder, LPCITEMIDLIST aPidl, DWORD aFlags, xpr_tchar_t *aName, xpr_size_t aMaxLen)
{
    STRRET  sStrRet = {0};
    HRESULT sComResult;

    sComResult = aShellFolder->GetDisplayNameOf(aPidl, aFlags, &sStrRet);
    if (SUCCEEDED(sComResult))
    {
        sComResult = ::StrRetToBuf(&sStrRet, aPidl, aName, (xpr_uint_t)aMaxLen);
        if (SUCCEEDED(sComResult))
        {
            return XPR_TRUE;
        }
    }

    return XPR_FALSE;
}
Exemplo n.º 8
0
// Gets the Display Name of a pidl. lpsf is the parent IShellFolder Interface
// dwFlags specify a SHGDN_xx value
BOOL IL_GetDisplayName(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidl, DWORD dwFlags,
                       WCHAR* lpszDisplayName, int nDisplayName) {

    STRRET str;

    if (NOERROR == lpsf->GetDisplayNameOf(pidl, dwFlags, &str)) {

        // Shlwapi.dll provides new function:
        return SUCCEEDED(StrRetToBufW(&str, pidl, lpszDisplayName, nDisplayName));
        // ...but I suppose my version is faster ;-)
        /*switch (str.uType)
        {

          case STRRET_WSTR:
            WideCharToMultiByte(CP_ACP,
                                0,
                                str.pOleStr,
                                -1,
                                lpszDisplayName,
                                nDisplayName,
                                NULL,
                                NULL);
            CoTaskMemFree(str.pOleStr);
            break;

          case STRRET_OFFSET:
            lstrcpyn(lpszDisplayName,
                     ((WCHAR *)(pidl)) + str.uOffset,
                     nDisplayName);
            break;

          case STRRET_CSTR:
            lstrcpyn(lpszDisplayName,str.cStr,nDisplayName);
            break;

        }

        return TRUE;*/
    }

    return FALSE;
}
Exemplo n.º 9
0
xpr_bool_t Pidl::getName(LPSHELLFOLDER aShellFolder, LPCITEMIDLIST aPidl, DWORD aFlags, xpr::string &aName)
{
    STRRET     sStrRet = {0};
    HRESULT    sComResult;
    xpr_bool_t sResult = XPR_FALSE;

    sComResult = aShellFolder->GetDisplayNameOf(aPidl, aFlags, &sStrRet);
    if (SUCCEEDED(sComResult))
    {
        switch (sStrRet.uType)
        {
        case STRRET_WSTR:
            {
#if defined(XPR_CFG_UNICODE)
                aName = sStrRet.pOleStr;
#else
                xpr_size_t sStringLength = wcslen(sStrRet.pOleStr);

                aName.clear();
                aName.reserve(sStringLength + 1);

                xpr_tchar_t *sName = (xpr_tchar_t *)aName.c_str();

                xpr_size_t sInputBytes = sStringLength * sizeof(xpr_wchar_t);
                xpr_size_t sOutputBytes = sStringLength * sizeof(xpr_tchar_t);
                XPR_UTF16_TO_MBS(sStrRet.pOleStr, &sInputBytes, sName, &sOutputBytes);
                sName[sOutputBytes / sizeof(xpr_tchar_t)] = 0;

                aName.update();
#endif
                sResult = XPR_TRUE;
                break;
            }

        case STRRET_CSTR:
        case STRRET_OFFSET:
            {
                const xpr_char_t *sString;
                switch (sStrRet.uType)
                {
                case STRRET_CSTR:
                    sString = sStrRet.cStr;
                    break;

                case STRRET_OFFSET:
                    sString = ((const xpr_char_t *)&aPidl->mkid) + sStrRet.uOffset;
                    break;

                default:
                    XPR_ASSERT(0);
                    break;
                }

                xpr_size_t sStringLength = strlen(sString);

                aName.clear();
                aName.reserve(sStringLength + 1);

                xpr_tchar_t *sName = (xpr_tchar_t *)aName.c_str();

                xpr_size_t sInputBytes = sStringLength * sizeof(xpr_char_t);
                xpr_size_t sOutputBytes = sStringLength * sizeof(xpr_tchar_t);
                XPR_MBS_TO_TCS(sStrRet.pOleStr, &sInputBytes, sName, &sOutputBytes);
                sName[sOutputBytes / sizeof(xpr_tchar_t)] = 0;

                aName.update();

                sResult = XPR_TRUE;
                break;
            }

        default:
            {
                sResult = XPR_FALSE;
                break;
            }
        }
    }

    return sResult;
}