Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Office toolbar item - Generic

Office toolbar item - Generic

Scheduled Pinned Locked Moved C / C++ / MFC
databasetestingtoolshelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ERLN
    wrote on last edited by
    #1

    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))
    {

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups