Bagikan melalui


Metode IUISimplePropertySet::GetValue (uiribbon.h)

Mengambil nilai yang diidentifikasi oleh kunci properti.

Sintaks

HRESULT GetValue(
  [in]  REFPROPERTYKEY key,
  [out] PROPVARIANT    *value
);

Parameter

[in] key

Jenis: REFPROPERTYKEY

Kunci Properti yang menarik.

[out] value

Jenis: PROPVARIANT*

Ketika metode ini kembali, berisi penunjuk ke nilai untuk kunci.

Nilai kembali

Jenis: HRESULT

Jika metode ini berhasil, metode ini mengembalikan S_OK. Jika tidak, kode kesalahan HRESULT akan dikembalikan.

Keterangan

Contoh

Contoh berikut menunjukkan implementasi kustom IUISimplePropertySet untuk galeri item dan Perintah.

Kelas CItemProperties dalam contoh ini berasal dari IUISimplePropertySet dan, selain metode yang diperlukan IUISimplePropertySet::GetValue, mengimplementasikan serangkaian fungsi pembantu untuk inisialisasi dan pelacakan indeks.

//
//  PURPOSE:    Implementation of IUISimplePropertySet.
//
//  COMMENTS:
//              Three gallery-specific helper functions added. 
//

class CItemProperties
  : public CComObjectRootEx<CComMultiThreadModel>
  , public IUISimplePropertySet
{
  public:

  // COM map for QueryInterface of IUISimplePropertySet.
  BEGIN_COM_MAP(CItemProperties)
    COM_INTERFACE_ENTRY(IUISimplePropertySet)
  END_COM_MAP()

  // Required method that enables property key values to be 
  // retrieved on gallery collection items.
  STDMETHOD(GetValue)(REFPROPERTYKEY key, PROPVARIANT *ppropvar)
  {
    HRESULT hr;

    // A Command gallery.
		  // _isCommandGallery set on item initialization.
    if (_isCommandGallery)
    {			
      if(key == UI_PKEY_CommandId && _isCommandGallery)
      {
			     // Return a pointer to the CommandId of the item.
        return InitPropVariantFromUInt32(_cmdID, ppropvar);
      }			
    }
    // An item gallery.
    else
    {
      if (key == UI_PKEY_Label)
      {
        // Return a pointer to the item label string.
        return UIInitPropertyFromString(
                 UI_PKEY_Label, g_labels[_index], ppropvar);
      }
      else if(key == UI_PKEY_ItemImage)
      {
        if (NULL == _spimgItem)
        {
          hr = CreateUIImageFromBitmapResource(
                 MAKEINTRESOURCE(IDB_GALLERYITEM), &_spimgItem);
          if (FAILED(hr))
          {
            return hr;
          }
        }
        // Return a pointer to the item image.
        return UIInitPropertyFromImage(
                 UI_PKEY_ItemImage, _spimgItem, ppropvar);
      }			
    }
    return E_NOTIMPL;
  }

  // Initialize an item in an item gallery collection at the specified index.
  void Initialize(int index)
  {
    _index = index;
    _cmdID = 0;
    _isCommandGallery = false;
  }

  // Initialize a Command in a Command gallery.
  void InitializeAsCommand(__in UINT cmdID)
  {
    _index = 0;
    _cmdID = cmdID;
    _isCommandGallery = true;
  }

  // Gets the index of the selected item in an item gallery.
  int GetIndex()
  {
    return _index;
  }

private:
  int _index;
  int _cmdID;
  bool _isCommandGallery;
  CComPtr<IUIImage> _spimgItem;	
};

Persyaratan

Persyaratan Nilai
Klien minimum yang didukung Windows 7 [hanya aplikasi desktop]
Server minimum yang didukung Windows Server 2008 R2 [hanya aplikasi desktop]
Target Platform Windows
Header uiribbon.h
DLL Mshtml.dll

Lihat juga

IUISimplePropertySet

Kunci Properti

Sampel Windows Ribbon Framework