Adding custom menu in Visio?

S

sh856531

Hi Guys,

I'm struggling to find out the best way to add a custom menu to Visio 2003
or Visio 2007. I've found the code in the Visio SDK and a few samples but my
problem is much more basic than that because as far as I can see, the SDK
doesn't actually tell you how the code gets executed, where you write it and
other such very basic things.

Could someone do me a huge favour and point me in the direction of some
resource that actually shows me the very basics, and doesn't assume I
implicitly know where to start entering my C# code....

Many thanks to anyone who can help

Simon
 
A

AlEdlund

I'd check John Marshall's site (visio.mvps.org) for a reading list (the
books by Parker, Edson, and Wideman are highly recommended). Most of the
example software out there is in some form of Visual Basic (since vba comes
free under the covers). If you're new to writing code for Visio I strongly
recommend learning the 'shapesheet' first (crawl before walk).
This is a good intro
http://msdn.microsoft.com/en-us/library/aa245244(office.10).aspx
al
 
S

sh856531

Hi Al,

Thank you very much for your answer.

I've bought a couple of books now and finally remembered about VSTO, so I'm
now gradually getting there - I've got forms appearing and what not.

I still havent quite got my menu working though because the
Application.CommandBars property that many of the samples seem to talk about
doesn't seem to be working properly. I don't know if it just doesnt work in
C# as all the examples are using VB of some variety.

Anywhoo - thanks again for your help!

Simon
 
J

JuneTheSecond

Yes, it is very hard for me to make a custom menu or tool button.
Menus and toolbuttons are at the lowest bottom of multistage hierarchy.
In each stage I count the members of collection and wrte out the caption or
name of each member. I always come at the target after step by step work.
 
S

sh856531

Hi June,

I have the following code which I think should work, but when I press F5 in
Visual Studio and Visio appears there is no new menu item. Do you have any
idea why that might be?

private void ThisAddIn_Startup(object sender, System.EventArgs e) {

// Base the new menu structure off of the current built in menu
structure. We need to keep a reference to this object to update the UI later
customMenuStructure = Application.BuiltInMenus;

// Get the menu set for the drawing window and add a new menu
primaryMenuSet =
Application.BuiltInMenus.MenuSets.get_ItemAtID(visUIObjSetDrawing);
customMenu = primaryMenuSet.Menus.AddAt(2);

customMenu.Caption = "This is my new menu";

menuItem = customMenu.MenuItems.Add();

menuItem.Caption = "Import XML";
menuItem.AddOnName = "Whatever";
menuItem.AddOnArgs = "Whatever";

Application.SetCustomMenus(customMenuStructure);

// Apparently this is required to update the menus with our
changes
customMenuStructure.UpdateUI();

}

Many thanks

Simon
 
G

gunslingor

Boy, programming with the visio drawing control is a pain in the @ss. I
am using VBA, drawing control inside Acces 2003 form.

1. Can someone explain to me a little more about these objects.

What is the difference between drawingcontrol0.window.application and
drawingcontrol0.document.application?

What is a document object? Is it the file? Or is it the opened instance
of the file? Or is it something else?

How about a window object? is it just the drawing control object on the
form, or is it a stencil window, a drawing window, the application
window, etc.

How do I reference, say, the drawing window?

What is the equivalent "show" command? is it "set"?

2. I am currently trying to have the drawing control show the standard
menus and toolbars that are opened when visio loads by itself (first).
And then also a simple and defined reliable way to customize these
menus.

Here is what I currently have:
'Object variables to be used
Dim uiObj As Visio.UIObject

'Get the UIObject object for the toolbars.
Set uiObj = vsoApp.BuiltInToolbars(0)
vsoApp.SetCustomToolbars uiObj
uiObj.UpdateUI

But no toolbars are added when I open the form. I have
negotiatemenues/toolbars=no because I want them to be displayed inside
the drawing control, not inside access.
 
A

AlEdlund

As a suggestion from the side. Before trying to run, one should learn to
walk. You have two application models that you are attempting to manipulate
simultaneously and both of them have some unique challanges. You might start
over here and begin to understand the visio object model and Visio documents
specifically.

http://msdn.microsoft.com/en-us/library/aa200958(office.10).aspx

To start with the activex control (not recommended as a first step, you
should understand Visio first)

http://msdn.microsoft.com/en-us/library/aa168480(office.11).aspx

John Marshall has a good list of books on his site (visio.mvps.org).

Have a great holiday,

al

ps I prefer the other approach, running Access under the covers from Visio
with VBA. It uses real forms.
 
G

gunslingor

I will look over that. I am on company time and they don't want to dish
out the money for books, so I am relying on free internet content. I
just found a good source in the visio 2002 SDK which is an entire book;
I am using 2003, however, and have some concerns about that.

Background. I an an I&C engineer with formal training in C++, Java, 4x
assembly. First project using VB or VBA, but I have been working for a
month.

Question. I sort of wish I had started this project in visual basic
2008, as a stand alone that used activeX controls and components from
visio and access (or some other database program). How hard would it be
to convert the project? How should I go about it?
 
G

gunslingor

Revised-I just checked out your links. Actually, I have read both of
those pages like 15 times trying to find clues to solve specific
problems. I guess I really need someone knowledgable to sit down with
me for an hour or so; that would really help.
 
G

gunslingor

I think I sent you a friend request. at (e-mail address removed). I think
you have to accept it before we can talk. I am at (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top