//------------------------------------------------------------------------------
// CDevicePropertyPage::GetIconFromItem [STATIC FUNC]
//
//      Gets a handle to the icon of the shell item. phIcon needs to be cleaned
//      up with DestroyIcon() when done. 
//------------------------------------------------------------------------------
HRESULT CDevicePropertyPage::GetIconFromItem(
    __in IShellItem* pShellItem, 
    __in int iImageList, 
    __out HICON* phIcon
    )
{
    HRESULT         hr              = S_OK;
    int             iIcon           = 0;
    PITEMID_CHILD   pidl            = NULL;
    IImageList*     pImageList      = NULL;
    IParentAndItem* pParentAndItem  = NULL;
    IShellFolder*   pShellFolder    = NULL;

    *phIcon = NULL;

    hr = pShellItem->QueryInterface( &pParentAndItem );

    if( S_OK == hr )
    {
        hr = pParentAndItem->GetParentAndItem( NULL, &pShellFolder, &pidl );
    }

    if( S_OK == hr )
    {
        hr = SHGetImageList(
            iImageList,
            __uuidof(IImageList),
            reinterpret_cast<void**>(&pImageList)
            );
    }

    if( S_OK == hr )
    {
        iIcon = SHMapPIDLToSystemImageListIndex( pShellFolder, pidl, NULL );
        hr = pImageList->GetIcon( iIcon, 0, phIcon );
    }

    //
    // Cleanup
    //
    if( NULL != pImageList )
    {
        pImageList->Release();
    }
    if( NULL != pidl )
    {
        ILFree( pidl );
    }
    if( NULL != pShellFolder )
    {
        pShellFolder->Release();
    }
    if( NULL != pParentAndItem )
    {
        pParentAndItem->Release();
    }

    return hr;
}// CDevicePropertyPage::GetIconFromItem
HRESULT CMenuSFToolbar::FillToolbar(BOOL clearFirst)
{
    HRESULT hr;

    CComPtr<IEnumIDList> eidl;
    hr = m_shellFolder->EnumObjects(GetToolbar(), SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &eidl);
    if (FAILED_UNEXPECTEDLY(hr))
        return hr;

    HDPA dpaSort = DPA_Create(10);

    LPITEMIDLIST item = NULL;
    hr = eidl->Next(1, &item, NULL);
    while (hr == S_OK)
    {
        if (m_menuBand->_CallCBWithItemPidl(item, 0x10000000, 0, 0) == S_FALSE)
        {
            DPA_AppendPtr(dpaSort, ILClone(item));
        }

        hr = eidl->Next(1, &item, NULL);
    }

    // If no items were added, show the "empty" placeholder
    if (DPA_GetPtrCount(dpaSort) == 0)
    {
        DPA_Destroy(dpaSort);
        return AddPlaceholder();
    }

    TRACE("FillToolbar added %d items to the DPA\n", DPA_GetPtrCount(dpaSort));

    DPA_Sort(dpaSort, PidlListSort, (LPARAM) m_shellFolder.p);

    for (int i = 0; i<DPA_GetPtrCount(dpaSort);)
    {
        PWSTR MenuString;

        INT index = 0;
        INT indexOpen = 0;

        STRRET sr = { STRRET_CSTR, { 0 } };

        item = (LPITEMIDLIST)DPA_GetPtr(dpaSort, i);

        hr = m_shellFolder->GetDisplayNameOf(item, SIGDN_NORMALDISPLAY, &sr);
        if (FAILED_UNEXPECTEDLY(hr))
        {
            DPA_Destroy(dpaSort);
            return hr;
        }

        StrRetToStr(&sr, NULL, &MenuString);

        index = SHMapPIDLToSystemImageListIndex(m_shellFolder, item, &indexOpen);

        LPCITEMIDLIST itemc = item;

        SFGAOF attrs = SFGAO_FOLDER;
        hr = m_shellFolder->GetAttributesOf(1, &itemc, &attrs);

        DWORD_PTR dwData = reinterpret_cast<DWORD_PTR>(item);

        // Fetch next item already, so we know if the current one is the last
        i++;

        AddButton(i, MenuString, attrs & SFGAO_FOLDER, index, dwData, i >= DPA_GetPtrCount(dpaSort));

        CoTaskMemFree(MenuString);
    }

    DPA_Destroy(dpaSort);
    return hr;
}
Beispiel #3
0
HRESULT STDMETHODCALLTYPE CAddressEditBox::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
    WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    CComPtr<IBrowserService> isb;
    CComPtr<IShellFolder> sf;
    HRESULT hr;
    INT indexClosed, indexOpen, itemExists, oldIndex;
    DWORD result;
    COMBOBOXEXITEMW item;
    PIDLIST_ABSOLUTE absolutePIDL;
    LPCITEMIDLIST pidlChild;
    LPITEMIDLIST pidlPrevious;
    STRRET ret;
    WCHAR buf[4096];

    if (pDispParams == NULL)
        return E_INVALIDARG;

    switch (dispIdMember)
    {
    case DISPID_NAVIGATECOMPLETE2:
    case DISPID_DOCUMENTCOMPLETE:
        pidlLastParsed = NULL;

        oldIndex = fCombobox.SendMessage(CB_GETCURSEL, 0, 0);

        itemExists = FALSE;
        pidlPrevious = NULL;

        ZeroMemory(&item, sizeof(item));
        item.mask = CBEIF_LPARAM;
        item.iItem = 0;
        if (fCombobox.SendMessage(CBEM_GETITEM, 0, reinterpret_cast<LPARAM>(&item)))
        {
            pidlPrevious = reinterpret_cast<LPITEMIDLIST>(item.lParam);
            if (pidlPrevious)
                itemExists = TRUE;
        }

        hr = IUnknown_QueryService(fSite, SID_STopLevelBrowser, IID_PPV_ARG(IBrowserService, &isb));
        if (FAILED_UNEXPECTEDLY(hr))
            return hr;

        hr = isb->GetPidl(&absolutePIDL);
        if (FAILED_UNEXPECTEDLY(hr))
            return hr;

        hr = SHBindToParent(absolutePIDL, IID_PPV_ARG(IShellFolder, &sf), &pidlChild);
        if (FAILED_UNEXPECTEDLY(hr))
            return hr;

        hr = sf->GetDisplayNameOf(pidlChild, SHGDN_FORADDRESSBAR | SHGDN_FORPARSING, &ret);
        if (FAILED_UNEXPECTEDLY(hr))
            return hr;

        hr = StrRetToBufW(&ret, pidlChild, buf, 4095);
        if (FAILED_UNEXPECTEDLY(hr))
            return hr;

        indexClosed = SHMapPIDLToSystemImageListIndex(sf, pidlChild, &indexOpen);

        item.mask = CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_TEXT | CBEIF_LPARAM;
        item.iItem = 0;
        item.iImage = indexClosed;
        item.iSelectedImage = indexOpen;
        item.pszText = buf;
        item.lParam = reinterpret_cast<LPARAM>(absolutePIDL);

        if (itemExists)
        {
            result = fCombobox.SendMessage(CBEM_SETITEM, 0, reinterpret_cast<LPARAM>(&item));
            oldIndex = 0;

            if (result)
            {
                ILFree(pidlPrevious);
            }
        }
        else
        {
            oldIndex = fCombobox.SendMessage(CBEM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&item));

            if (oldIndex < 0)
                DbgPrint("ERROR %d\n", GetLastError());
        }

        fCombobox.SendMessage(CB_SETCURSEL, -1, 0);
        fCombobox.SendMessage(CB_SETCURSEL, oldIndex, 0);

        //fAddressEditBox->SetCurrentDir(index);
    }
    return S_OK;
}