MuLLeR

Hi,

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#.

Configuration:

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)

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");

this.vsoApplication.SetCustomMenus(this.builtInMenus);

MainForm frm = new MainForm();

frm.ShowDialog();

}

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

System.Windows.Forms.MessageBox.Show("TEEEEST");

((Event)pSourceObj).EventList.get_ItemFromID(nEventID);

return null;

}

#endregion

}

}



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:

http://www.microsoft.com/office/community/en-us/default.mspx dg=microsoft.public.office.developer.com.add_ins&lang=en&cr=US

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

http://support.microsoft.com/kb/303018/en-us






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

MuLLeR

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:

http://www.microsoft.com/office/community/en-us/default.mspx query=MenuItem&dg=microsoft.public.office.developer.com.add_ins&cat=en-us-office-officedeveloper&lang=en&cr=US&pt=3a4e9862-cdce-4bdc-8664-91038e3eb1e9&catlist=B7714BAA-0D60-40B0-A226-8B9CF33299A5&dglist=&ptlist=&exp=&sloc=en-us





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

MuLLeR

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

http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.visio.developer&lang=en&cr=US