I've managed to create a COM add-on for the MS Office Visio 12, the add-on loads correctly on Visio start-up, i've managed to add a Menu with SubMenus to the Visio MenuBar, the question is:

How to get the event when user clicks the MenuItems

I've seen some examples with AddAdvise written in VBA, but i'm using C#.


MS Visio 2007 Trial,

MS VS 2005 C# Express

Vista Business

The Code:

namespace DQTeam.Office.Visio.Addin.PEVI {

using System;

using System.Runtime.InteropServices;

using Extensibility;

using Microsoft.Office.Core;

using Microsoft.Office.Interop.Visio;

using System.Runtime.InteropServices.ComTypes;

/// <summary>This class implements the IDTExtensibility2 interface in order

/// to connect to Microsoft Visio as a COM add-in.</summary>

[GuidAttribute("9ED54F84-A89D-4fcd-A854-44251E925F09"), ProgId("DQTeam.Office.Visio.Addin.PEVI.Connect")]

public class Connect : Object, Extensibility.IDTExtensibility2, IVisEventProc {

private Microsoft.Office.Interop.Visio.Application vsoApplication;

private object addInInstance;

private UIObject builtInMenus;

private IAdviseSink mEventSink;

/// <summary>This constructor intentionally left blank.</summary>

public Connect() {

// No initialization required.


public void OnAddInsUpdate(ref System.Array custom) {


public void OnBeginShutdown(ref System.Array custom) {


public void OnConnection(

object application,

Extensibility.ext_ConnectMode connectMode,

object addInInst,

ref System.Array custom) {

vsoApplication = (Microsoft.Office.Interop.Visio.Application)


addInInstance = addInInst;

this.builtInMenus = vsoApplication.BuiltInMenus;

MenuSets menuSets = this.builtInMenus.MenuSets;

MenuSet menuSet = menuSets.get_ItemAtID((int)VisUIObjSets.visUIObjSetDrawing);

Menus menus = menuSet.Menus;

Menu menu = menus.AddAt(7);

menu.Caption = "Test Pevi Menu";

MenuItems menuItems = menu.MenuItems;

MenuItem menuItem = menuItems.Add();

menuItem.Caption = "&Start";

this.vsoApplication.EventList.AddAdvise(12, this.mEventSink, "", "None");


MainForm frm = new MainForm();



public void OnDisconnection(

Extensibility.ext_DisconnectMode disconnectMode,

ref System.Array custom) {


public void OnStartupComplete(ref System.Array custom) {


#region IVisEventProc Members

public object VisEventProc(short nEventCode, object pSourceObj, int nEventID, int nEventSeqNum, object pSubjectObj, object vMoreInfo) {



return null;





Re: Visual Studio Tools for Office Office 12 COM AddOns Events

Cindy Meister

This forum is actually targeted at a different kind of Add-in. COM Add-ins based on the "Shared Add-in" template, that you're using, are supported in the newsgroup interface:

From the looks of it, the problem is how you're declaring / creating the buttons for the toolbar.

1. You need to declare the object variables for the buttons at the class level. If you declare them inside a procedure they'll eventually go out of scope and get garbage collected.

2. You need to setup the CLICK event.

See if this Knowledge Base article gets you along a bit further

Re: Visual Studio Tools for Office Office 12 COM AddOns Events


ok, that's clear how to set the click event for the CommandBarButton,

but can we set the event for the MenuItem

ok thanx .. found what i was looking for in the newsletter

here's the link: query=MenuItem&

Re: Visual Studio Tools for Office Office 12 COM AddOns Events


Is it possible to set an C# OnDoubleClick Event to a shape in Visio

the function/procedure must be handled in C# AddOn.

Re: Visual Studio Tools for Office Office 12 COM AddOns Events

Cindy Meister

That would depend on whether Visio exposes such an event. If it does, then you can.

Best place to find out would be the Visio developer newsgroup dg=microsoft.public.visio.developer&lang=en&cr=US