2025-11-28 00:35:46 +09:00

124 lines
3.0 KiB
C++

// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
#include <UIRibbon.h>
#include "CommandHandler.h"
#include "SimpleRibbonUI.h"
#include "RibbonFramework.h"
// Static method to create an instance of the object.
__checkReturn HRESULT CCommandHandler::CreateInstance(__deref_out IUICommandHandler **ppCommandHandler)
{
if (!ppCommandHandler)
{
return E_POINTER;
}
*ppCommandHandler = NULL;
HRESULT hr = S_OK;
CCommandHandler* pCommandHandler = new CCommandHandler();
if (pCommandHandler != NULL)
{
*ppCommandHandler = static_cast<IUICommandHandler *>(pCommandHandler);
}
else
{
hr = E_OUTOFMEMORY;
}
return hr;
}
// IUnknown method implementations.
STDMETHODIMP_(ULONG) CCommandHandler::AddRef()
{
return InterlockedIncrement(&m_cRef);
}
STDMETHODIMP_(ULONG) CCommandHandler::Release()
{
LONG cRef = InterlockedDecrement(&m_cRef);
if (cRef == 0)
{
delete this;
}
return cRef;
}
STDMETHODIMP CCommandHandler::QueryInterface(REFIID iid, void** ppv)
{
if (iid == __uuidof(IUnknown))
{
*ppv = static_cast<IUnknown*>(this);
}
else if (iid == __uuidof(IUICommandHandler))
{
*ppv = static_cast<IUICommandHandler*>(this);
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
//
// FUNCTION: UpdateProperty()
//
// PURPOSE: Called by the Ribbon framework when a command property (PKEY) needs to be updated.
//
// COMMENTS:
//
// This function is used to provide new command property values, such as labels, icons, or
// tooltip information, when requested by the Ribbon framework.
//
// In this SimpleRibbon sample, the method is not implemented.
//
STDMETHODIMP CCommandHandler::UpdateProperty(
UINT nCmdID,
__in REFPROPERTYKEY key,
__in_opt const PROPVARIANT* ppropvarCurrentValue,
__out PROPVARIANT* ppropvarNewValue)
{
UNREFERENCED_PARAMETER(nCmdID);
UNREFERENCED_PARAMETER(key);
UNREFERENCED_PARAMETER(ppropvarCurrentValue);
UNREFERENCED_PARAMETER(ppropvarNewValue);
return E_NOTIMPL;
}
//
// FUNCTION: Execute()
//
// PURPOSE: Called by the Ribbon framework when a command is executed by the user. For example, when
// a button is pressed.
//
STDMETHODIMP CCommandHandler::Execute(
UINT nCmdID,
UI_EXECUTIONVERB verb,
__in_opt const PROPERTYKEY* key,
__in_opt const PROPVARIANT* ppropvarValue,
__in_opt IUISimplePropertySet* pCommandExecutionProperties)
{
UNREFERENCED_PARAMETER(pCommandExecutionProperties);
UNREFERENCED_PARAMETER(ppropvarValue);
UNREFERENCED_PARAMETER(key);
UNREFERENCED_PARAMETER(verb);
UNREFERENCED_PARAMETER(nCmdID);
return S_OK;
}