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 |