Click here to Skip to main content
Licence CPOL
First Posted 29 Feb 2008
Views 21,113
Downloads 170
Bookmarked 10 times

Create Visio Add-on VSL project with Toolbar, Menu and Command Handler

By | 29 Feb 2008 | Article
An article on a Visio Add-on VSL project that is focussed on speed

Introduction

VSL add-ons: VSL’s (ViSio Libraries) were first made available with Visio 2.0. In fact, many of the out-of-the-box Visio solutions, such as the Organization Chart, are implemented as a VSL add-on. You create VSL add-ons using C or C++. The emphasis of this Visio solution option is sheer speed. Bear in mind, Visio SDK needs to installed to use this.

Using the Code

Procedure to Create an Application

Create a new project using Microsoft Visual 2005 Editor. Navigate to Other Languages and choose Visual C++. This will display many options with Visio add-in or add-on and select it. Provide the project a name, like "VisioProject1." This pops up the Microsoft Visio Add-in or Add-on Wizard. Click the Next button, choose "Create a Visio VSL add-on, Use C++ without ATL of MFC," Click Next, Choose "Import Visio type library," and Click Next and Finish the Wizard. The Wizard generates sample code. When running the Add-on, Message Box will be displayed with the information that "VisioProject1 add-on generated by Visio 2007 SDK Add-in/Add-on Wizard VisioProject1." Comment out the MessageBox code and add the following source code to implement the customized menu, Toolbar and handling the MenuItem, ToolbarItem functionalities. Build the project. It generates the VisioProject1.vsl binary file in the Debug folder.

//Common
BSTR bstrAddOnName = SysAllocString(L"VisioProject1U"); 
BSTR bstrTitle = SysAllocString(L"&Sample"); 
BSTR bstrItem = SysAllocString(L"Item");

//Menu: Visio::IVUIObjectPtr uiObjPtr; 
Visio::IVMenuSetsPtr menuSetsPtr; 
Visio::IVMenuSetPtr menuSetPtr; 
Visio::IVMenusPtr menusPtr; 
Visio::IVMenuPtr menuPtr; 
Visio::IVMenuItemsPtr menuItemsPtr; 
Visio::IVMenuItemPtr menuItemPtr;

hr = m_app->get_BuiltInMenus(&uiObjPtr); 
hr = uiObjPtr->get_MenuSets(&menuSetsPtr); 
//long itemId = Visio::VisUIObjSets::visUIObjSetDrawing; 
hr = menuSetsPtr->get_ItemAtID(2, &menuSetPtr); 
hr = menuSetPtr->get_Menus(&menusPtr); //add a new menu 
menuPtr = menusPtr->AddAt(7); 
hr = menuPtr->put_Caption(bstrTitle); 
hr = menuPtr->get_MenuItems(&menuItemsPtr); 
//MenuItem1 menuItemPtr = menuItemsPtr->Add(); 
hr = menuItemPtr->put_Caption(bstrItem); 
menuItemPtr->put_AddOnName(bstrAddOnName); 
//Add-on name 
menuItemPtr->put_ActionText(bstrItem); 
menuItemPtr->put_MiniHelp(bstrItem); 
menuItemPtr->put_AddOnArgs(bstrItem); 
m_app->SetCustomMenus(uiObjPtr); //Add the Menu to the Application

//Toolbar

Visio::IVUIObjectPtr uiToolbarPtr; 
Visio::IVToolbarSetPtr toolbarSetPtr; 
Visio::IVToolbarPtr toolbarPtr; 
Visio::IVToolbarItemsPtr toolbarItemsPtr; 
Visio::IVToolbarItemPtr toolbarItemPtr;

// get build in toolbars 
hr = m_app->get_BuiltInToolbars(0, &uiToolbarPtr); 
hr = uiToolbarPtr->ToolbarSets->get_ItemAtID(2, &toolbarSetPtr); //add a new toolbar 
toolbarPtr = toolbarSetPtr->Toolbars->Add(); 
toolbarPtr->put_Caption(bstrTitle); 
//toolbarPtr->put_Position((short)Visio::VisUIBarPosition::visBarMenu); 
toolbarPtr->put_Position(6); 
hr = toolbarPtr->get_ToolbarItems(&toolbarItemsPtr); 
//ToolbarItem1 
toolbarItemPtr = toolbarItemsPtr->Add(); 
toolbarItemPtr->put_Caption(bstrItem); 
toolbarItemPtr->put_AddOnName(bstrAddOnName); 
//Add-on Name toolbarItemPtr->put_ActionText(bstrItem); 
toolbarItemPtr->put_MiniHelp(bstrItem); 
toolbarItemPtr->put_AddOnArgs(bstrItem); 
toolbarItemPtr->put_CntrlType(2); 
//(int)Visio.VisUICtrlTypes.visCtrlTypeBUTTON;
toolbarItemPtr->put_FaceID(270);
m_app->SetCustomToolbars(uiToolbarPtr); //Add the Toolbar to the Application


Command Handling
    //Handling the User click commands from Visio - Command Handler     
        if (pV2L->szCmdLineArgs != NULL){
            if (strcmp(pV2L->szCmdLineArgs, "Item") == 0){
            MessageBoxA(0, pV2L->szCmdLineArgs, "Info", 0);

            }
        }

To Run

Open the Visio Application. Navigate to Tools->Option->Advanced then File Paths. Add the file path of VisioProject1.vsl in the Add-ons path and click OK. Close and reopen the the Visio application. Navigate to Tools->Add-ons. Select the VisioProject1 in the Run Add-On popup window. Click OK to run the Add-on. You can see the customized Toolbar and Menu in the Visio application as I mention in the picture. If you click on the menu or toolbar item then it will display the Message Box with Item name.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Member 480838

Software Developer (Senior)

India India

Member

I am working with Microsoft Technologies.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberDieter Sternberg0:20 3 Apr '09  
GeneralComplete garbage PinmemberBert delaVega11:45 29 Feb '08  
GeneralRe: Complete garbage PinmemberChunlong lin14:35 29 Feb '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 29 Feb 2008
Article Copyright 2008 by Member 480838
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid