Office toolbar item - Generic
-
Hi ! I have using the following code for creating the toolbar button for office 2000 to office 2003. It is generic. So I am using this code. Actually I need 2 buttons in 1 single toolbar. how to do that. Also Help to how to add the same in file menu item. and also it should work office 2000 to office 2003. Give a solution for this. also following code object model is like this commandbars("standard").controls.add (,,,,,) how to change the code refer like this commandbars(0).controls(2).add. I have tried to add "Index as property" but no use
STDMETHODIMP CSampleAddin::AddToolBarButton(LPOLESTR lpToolBarName,LPOLESTR lpButtonName,LPOLESTR lpToolTip,LPOLESTR lpTag,long lFaceId,long lBitmapResource)
{
TCHAR szTest[MAX_PATH]={0};
// Add a new CommandBar and Button using Automation...
VARIANT vtCmdBars; VariantInit(&vtCmdBars);
VARIANT vtCmdBar; VariantInit(&vtCmdBar);
VARIANT vtCtrls; VariantInit(&vtCtrls);
VARIANT vtButton; VariantInit(&vtButton);
VARIANT vtParam; VariantInit(&vtParam);
VARIANT vtButton1; VariantInit(&vtButton1);
VARIANT vtExp; VariantInit(&vtExp);
HRESULT hr = S_FALSE;ZeroMemory(szTest,sizeof(szTest)); hr = GetProperty(m\_pParentApp, L"CommandBars", &vtCmdBars); if (FAILED(hr)) goto cleanup;
// Look for our command bar -- this prevents us from making a new one
// if the old one was never deleted.
vtParam.vt = VT_BSTR; vtParam.bstrVal = ::SysAllocString(lpToolBarName);
hr = CallMethod(vtCmdBars.pdispVal, L"Item", &vtCmdBar, 1, &vtParam);
VariantClear(&vtParam);// If we can't find it, make a new bar...
if (FAILED(hr)) {
vtParam.vt = VT_BSTR; vtParam.bstrVal = ::SysAllocString(lpToolBarName);
hr = CallMethod(vtCmdBars.pdispVal, L"Add", &vtCmdBar, 1, &vtParam);
VariantClear(&vtParam);
if (FAILED(hr)) goto cleanup;
}// Store a reference...
m_pOurCmdBar[nCount] = vtCmdBar.pdispVal;
m_pOurCmdBar[nCount]->AddRef();hr = GetProperty(m\_pOurCmdBar\[nCount\], L"Controls", &vtCtrls); if (FAILED(hr)) goto cleanup;
// Grab our button to sink events...
vtParam.vt = VT_BSTR; vtParam.bstrVal = ::SysAllocString(lpButtonName);
hr = CallMethod(vtCtrls.pdispVal, L"Item", &vtButton, 1, &vtParam);
VariantClear(&vtParam);\_stprintf(szTest,TEXT("Value of hr at button item is (Item): %X"),hr); OutputDebugString(szTest);
// If we can't find it, make a new button...
if (FAILED(hr))
{