Ejemplo n.º 1
0
std::wstring OsShell::toolTip(std::wstring itemPath)
{
	ComInitializer comInitializer;

	std::replace(itemPath.begin(), itemPath.end(), '/', '\\');
	std::wstring tipString;
	ITEMIDLIST * id = 0;
	HRESULT result = SHParseDisplayName(itemPath.c_str(), 0, &id, 0, 0);
	if (!SUCCEEDED(result) || !id)
		return tipString;
	CItemIdListReleaser idReleaser (id);

	LPCITEMIDLIST child = 0;
	IShellFolder * ifolder = 0;
	result = SHBindToParent(id, IID_IShellFolder, (void**)&ifolder, &child);
	if (!SUCCEEDED(result) || !child)
		return tipString;

	IQueryInfo* iQueryInfo = 0;
	if (SUCCEEDED(ifolder->GetUIObjectOf(NULL, 1, &child, IID_IQueryInfo, 0, (void**)&iQueryInfo)) && iQueryInfo)
	{
		LPWSTR lpszTip = 0;
		CComInterfaceReleaser releaser (iQueryInfo);
		if (SUCCEEDED(iQueryInfo->GetInfoTip(0, &lpszTip)) && lpszTip)
		{
			tipString = lpszTip;
			CoTaskMemFree(lpszTip);
		}
	}

	std::replace(tipString.begin(), tipString.end(), '\r', '\n');
	return tipString;
}
Ejemplo n.º 2
0
xpr_bool_t Pidl::getInfotip(LPSHELLFOLDER aShellFolder, LPCITEMIDLIST aPidl, xpr::string &aInfotip)
{
    xpr_bool_t  sResult    = XPR_FALSE;
    IQueryInfo *sQueryInfo = XPR_NULL;
    HRESULT     sComResult;

    sComResult = aShellFolder->GetUIObjectOf(
        XPR_NULL,
        1,
        (LPCITEMIDLIST *)&aPidl,
        IID_IQueryInfo,
        0,
        (LPVOID *)&sQueryInfo);

    if (SUCCEEDED(sComResult) && XPR_IS_NOT_NULL(sQueryInfo))
    {
        xpr_wchar_t *sWideInfotip = XPR_NULL;

        sComResult = sQueryInfo->GetInfoTip(SHGDN_INFOLDER, &sWideInfotip);
        if (SUCCEEDED(sComResult) && XPR_IS_NOT_NULL(sWideInfotip))
        {
            xpr_size_t sInfotipLen = wcslen(sWideInfotip);
            if (sInfotipLen != 0)
            {
                aInfotip.clear();
                aInfotip.reserve(sInfotipLen + 1);

                xpr_tchar_t *sInfotip = (xpr_tchar_t *)aInfotip.c_str();

                xpr_size_t sInputBytes = sInfotipLen * sizeof(xpr_wchar_t);
                xpr_size_t sOutputBytes = sInfotipLen * sizeof(xpr_tchar_t);
                XPR_UTF16_TO_TCS(sWideInfotip, &sInputBytes, sInfotip, &sOutputBytes);
                sInfotip[sOutputBytes / sizeof(xpr_tchar_t)] = 0;

                aInfotip.update();

                sResult = XPR_TRUE;
            }
        }

        COM_FREE(sWideInfotip);
    }

    COM_RELEASE(sQueryInfo);

    return sResult;
}