IUISimplePropertySet::GetValue 方法 (uiribbon.h)
擷取屬性索引鍵所識別的值。
語法
HRESULT GetValue(
[in] REFPROPERTYKEY key,
[out] PROPVARIANT *value
);
參數
[in] key
類型: REFPROPERTYKEY
感興趣的 屬性索引鍵 。
[out] value
類型: PROPVARIANT*
當這個方法傳回時,會包含 索引鍵值的指標。
傳回值
類型: HRESULT
如果此方法成功,則會傳回 S_OK。 否則,它會傳回 HRESULT 錯誤碼。
備註
範例
下列範例示範專案和 Command 資源庫 的 IUISimplePropertySet 自定義實作。
此範例中的 CItemProperties 類別衍生自 IUISimplePropertySet ,除了必要的 IUISimplePropertySet::GetValue 方法之外,還會實作一組協助程式函式來進行初始化和索引追蹤。
//
// 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;
};
規格需求
需求 | 值 |
---|---|
最低支援的用戶端 | Windows 7 [僅限傳統型應用程式] |
最低支援的伺服器 | Windows Server 2008 R2 [僅限桌面應用程式] |
目標平台 | Windows |
標頭 | uiribbon.h |
Dll | Mshtml.dll |