M
mwiles
I am updating my COM project to use the ribbon instead of the commandbar for
Office 2007. I used to have the behavior that I can enable / disable
buttons as needed. I have read about Invalidate & InvalideControl for the
RibbonControl but am getting undesired results when executing the following
test code. I have copied snippits of code from my project ...
LPDISPATCH m_pRibbonUI;
STDMETHODIMP MyRibbon::OnLoad(LPDISPATCH pRibbonUI)
{
// store a reference to the parm to invalidate the UI
// in certain cases buttons may need to be disabled and
// invalidating will refresh the ribbon
m_pRibbonUI = pRibbonUI;
if( m_pRibbonUI )
m_pRibbonUI->AddRef();
return S_OK;
}
void MyRibbon::ButtonClick()
{
InvalidateRibbon();
}
void MyRibbon::InvalidateRibbon()
{
if( m_pRibbonUI )
{
HRESULT hr;
VARIANT vtRtn; VariantInit(&vtRtn);
DISPID dwDispID;
DISPPARAMS dispparams = {NULL, NULL, 0, 0};
dispparams.rgvarg = NULL;
dispparams.cArgs = 0;
EXCEPINFO eInfo;
UINT uInt;
hr = m_pRibbonUI->GetIDsOfNames(IID_NULL, "Invalidate", 1,
LOCALE_USER_DEFAULT, &dwDispID);
if ( SUCCEEDED(hr) )
hr = m_pRibbonUI->Invoke(dwDispID, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &dispparams, &vtRtn, &eInfo, &uInt);
}
}
I am able to get the correct ID for the methods Invalide (1) InvalideControl
(2) ... but when I call either of them, Invalidate with no parms, Invalidate
with one VT_BSTR parm of the ControlID in the RibbonXML, I get the following
returncode dec:-2146827864
Any help would be greatly appreciated... I am at a loss.
Office 2007. I used to have the behavior that I can enable / disable
buttons as needed. I have read about Invalidate & InvalideControl for the
RibbonControl but am getting undesired results when executing the following
test code. I have copied snippits of code from my project ...
LPDISPATCH m_pRibbonUI;
STDMETHODIMP MyRibbon::OnLoad(LPDISPATCH pRibbonUI)
{
// store a reference to the parm to invalidate the UI
// in certain cases buttons may need to be disabled and
// invalidating will refresh the ribbon
m_pRibbonUI = pRibbonUI;
if( m_pRibbonUI )
m_pRibbonUI->AddRef();
return S_OK;
}
void MyRibbon::ButtonClick()
{
InvalidateRibbon();
}
void MyRibbon::InvalidateRibbon()
{
if( m_pRibbonUI )
{
HRESULT hr;
VARIANT vtRtn; VariantInit(&vtRtn);
DISPID dwDispID;
DISPPARAMS dispparams = {NULL, NULL, 0, 0};
dispparams.rgvarg = NULL;
dispparams.cArgs = 0;
EXCEPINFO eInfo;
UINT uInt;
hr = m_pRibbonUI->GetIDsOfNames(IID_NULL, "Invalidate", 1,
LOCALE_USER_DEFAULT, &dwDispID);
if ( SUCCEEDED(hr) )
hr = m_pRibbonUI->Invoke(dwDispID, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &dispparams, &vtRtn, &eInfo, &uInt);
}
}
I am able to get the correct ID for the methods Invalide (1) InvalideControl
(2) ... but when I call either of them, Invalidate with no parms, Invalidate
with one VT_BSTR parm of the ControlID in the RibbonXML, I get the following
returncode dec:-2146827864
Any help would be greatly appreciated... I am at a loss.