Office.CommandBars VS. Visio.ToolbarItems and Visio.MenuItems

S

SomeNewDev

Hello,

yesterday I saw this webcast about 'Visio 2007 for developers' by Senaj Lelic.
It was recommended _NOT_ to use the CommandBars in Visio add-ins coz of bugs.
And yes, seems I've already noticed them acting wild sometimes.

So I switched to Visio's ToolbarItems and MenuItems collections.
Adding them works ok so far. But it was NOT shown how to add events
to their items, and I still can't figure it out.

Well, in the SDK only CommandBars are used... nowhere to look it up then :?

Could somebody post a snippet please ?
Thanks.

PS: This is what I've got so far:

[...]
Visio.UIObject VisioUIO;
Visio.MenuSet CurrentVisioMenuSet;
Visio.Menu FMVisioMenu;
Visio.MenuItems menuItems;
Visio.MenuItem menuItem;

VisioApp = Application;

if (Application.CustomMenus != null)
VisioUIO = Application.CustomMenus;
else
VisioUIO = Application.BuiltInMenus;

CurrentVisioMenuSet = VisioUIO.MenuSets.get_ItemAtID(
(int)Visio.VisUIObjSets.visUIObjSetDrawing);

FMVisioMenu = CurrentVisioMenuSet.Menus.AddAt(8);
FMVisioMenu.Caption = "&My Menu";
menuItems = FMVisioMenu.MenuItems;
menuItem = menuItems.Add();
menuItem.Caption = "&Start";

VisioApp.SetCustomMenus(VisioUIO);
[...]
 
P

Paul Herber

Hello,

yesterday I saw this webcast about 'Visio 2007 for developers' by Senaj Lelic.
It was recommended _NOT_ to use the CommandBars in Visio add-ins coz of bugs.
And yes, seems I've already noticed them acting wild sometimes.

So I switched to Visio's ToolbarItems and MenuItems collections.
Adding them works ok so far. But it was NOT shown how to add events
to their items, and I still can't figure it out.

Well, in the SDK only CommandBars are used... nowhere to look it up then :?

Could somebody post a snippet please ?
Thanks.

PS: This is what I've got so far:

[...]
Visio.UIObject VisioUIO;
Visio.MenuSet CurrentVisioMenuSet;
Visio.Menu FMVisioMenu;
Visio.MenuItems menuItems;
Visio.MenuItem menuItem;

VisioApp = Application;

if (Application.CustomMenus != null)
VisioUIO = Application.CustomMenus;
else
VisioUIO = Application.BuiltInMenus;

CurrentVisioMenuSet = VisioUIO.MenuSets.get_ItemAtID(
(int)Visio.VisUIObjSets.visUIObjSetDrawing);

FMVisioMenu = CurrentVisioMenuSet.Menus.AddAt(8);
FMVisioMenu.Caption = "&My Menu";
menuItems = FMVisioMenu.MenuItems;
menuItem = menuItems.Add();
menuItem.Caption = "&Start";

VisioApp.SetCustomMenus(VisioUIO);


Hi, for each menuItem you need to set the menuItem.AddOnName to the
name of the addon that handles this menu. You can either have an addon
for each menu entry or use just one addon and then use the
menuItem.AddOnArgs to tell the addon what to do.
 
S

SomeNewDev

Hi,

and sorry.. what I meant was, if there's a way to get an event !
I want to execute my own procedures inside of _my_ add-in,
not any extern add-ons.
So maybe this is supposed to work only for executing extern add-ons :?
Looks like sticking with the commandbars..

regards
 
P

Paul Herber

Hi,

and sorry.. what I meant was, if there's a way to get an event !
I want to execute my own procedures inside of _my_ add-in,
not any extern add-ons.
So maybe this is supposed to work only for executing extern add-ons :?

Sorry, I'm not at sure what you mean. I thought you were writing about
menu handlers. What event? What do you mean by "get an event". Doing
certain things causes events. You can tell Visio that you wish to
handle a certain event and you can write code to handle that event.

The "event" of clicking a menu is handled by standard menu handlers,
inside your own addon.
 
S

SomeNewDev

Paul Herber said:
Sorry, I'm not at sure what you mean. I thought you were writing about
menu handlers. What event? What do you mean by "get an event". Doing
certain things causes events. You can tell Visio that you wish to
handle a certain event and you can write code to handle that event.

The "event" of clicking a menu is handled by standard menu handlers,
inside your own addon.

Hi,

I mean, if I'm using a CommandBar in my Add-in, then I got a ".Click" event:

[...]
public Office.CommandBarButton mbiOpenDoc;
[...]
mbiOpenDoc.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(tbOpenDoc_Click);
[...]

But for a Visio.MenuItem I got NO such events, only stuff like "ActionText"
or "AddOnName".

I hope my question is clearer now. I should have mentioned that I'm
working with VSTO SE. Maybe such events are added in VSTO 3.0 ???

thanks
 
P

Paul Herber

Paul Herber said:
Sorry, I'm not at sure what you mean. I thought you were writing about
menu handlers. What event? What do you mean by "get an event". Doing
certain things causes events. You can tell Visio that you wish to
handle a certain event and you can write code to handle that event.

The "event" of clicking a menu is handled by standard menu handlers,
inside your own addon.

Hi,

I mean, if I'm using a CommandBar in my Add-in, then I got a ".Click" event:

[...]
public Office.CommandBarButton mbiOpenDoc;
[...]
mbiOpenDoc.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(tbOpenDoc_Click);
[...]

But for a Visio.MenuItem I got NO such events, only stuff like "ActionText"
or "AddOnName".

Yes, that's it, the AddOnName. It's not very accurate as this is the
name of the procedure that handles this menu.
When the menu is clicked then the procedure you set in AddOnName gets
called.
 
S

SomeNewDev

Hi,

ah, then it is possible ! But that's exactly where I'm still stuck.
I tried everything possible to set into this AddOnName.
For instance if I want it to call 'MyProcedure'.. what exactly
would I need to put into AddOnName ??? That's why I was asking,
if somebody would be so kind to post a snippet, coz I couldn't
get it working that way !

[...]
menuItem = menuItems.Add();
menuItem.Caption = "&Start";
menuItem.AddOnName = "MyProcedure";
[...]
MyProcedure()
{
}
[...]

So the current situation is following:
My menu entry + menu item is visible and activated, but
whenever I fill any value into AddOnName, then the menuitem
is deactivated ! So I guess I never found a valid value to fill
into AddOnName. And I also tried it with namespace + class name.
Also with or without parameters.

Please could somebody post these 3 lines of snippet for dummies ! :--)

Thanks
 
N

Nikolay Belyh

I think that UIObjects might be even *worse* than command bars...
Actually today I'm thinking of migrating all our UI to CommandBars
from UIObjects.. For all weird stuff about command bars, there are
known workarounds. And if you don't need a document-level menu
customizations, are "tough enough" and won't fall into silly traps
like the one on next the picture, I fail to see any problems with
programming using command bars... :)
http://pix.academ.org/img/2008/09/15/680b0138b74d561348a2d0675397132f

As for UIObject model, I also thought it is a "silver bullet" until
discovered a "fatal flaw" (sic!) in it... Unfortunately I am still
unable to overcome that issue (see the very last post to the following
thread for detailed info). So beware! (though this issue that turned
out to be "fatal" for me might be of no importance for the majority of
developers)...
http://groups.google.com/group/micr...veloper/browse_thread/thread/ba9a0265afc1541b

Kind regards, Nikolay.

SomeNewDev:
 
N

Nikolay Belyh

ah, then it is possible ! But that's exactly where I'm still stuck.
I tried everything possible to set into this AddOnName.
For instance if I want it to call 'MyProcedure'.. what exactly
would I need to put into AddOnName ??? That's why I was asking,
if somebody would be so kind to post a snippet, coz I couldn't
get it working that way !

Basically, you need an ADDON to use ADDONNAME property.
As far as I can see you have VSTO-based ADDIN and not ADDON. There IS
a difference ;-)

You have the following options:

- (using CommandBars) Simply use Click event for the button and set
TAG property to some unique value (this shall protect your "Click"
event from "accidental death", this is the "trap" mentioned in my
previous post). For more info about that, take (a closer) look here:
http://msdn.microsoft.com/en-us/library/aa201791.aspx

- (using UIObjects or CommandBars) use AddonName, and put
"QueueMarkerEvent" word there. This is the name of built-in ADDON
capable of sending marker events. Then put something unique to
"AddonArguments", subscribe to Application.MarkerEvent event, and in
the event handler check if the value passed to it matches the value
you put to "AddonArguments". If it does, then your menu item was
clicked. Here is more info:
http://msdn.microsoft.com/en-us/library/aa140366.aspx

Anyways, AFAIK the next release of Visio will use "Fluent UI" (or how
do you call those "fist-sized" ribbon buttons)... :)
Considering that, I'm not really sure what would be easier to port to
the Ribbon - CommandBars or UIObjects...? Will the UIObjects/
CommandBars API even supported in the "ribboned" visio?

Kind regards, Nikolay.
 
S

SomeNewDev

Hi Nikolay,

big thanks for your replies.. very informative and funny !
Got it working now with "QueueMarkerEvent". Yes, I need
document-level menus, so also thanks for the warning :">

Best regards.


Nikolay Belyh said:
I think that UIObjects might be even *worse* than command bars...
Actually today I'm thinking of migrating all our UI to CommandBars
from UIObjects.. For all weird stuff about command bars, there are
known workarounds. And if you don't need a document-level menu
customizations, are "tough enough" and won't fall into silly traps
like the one on next the picture, I fail to see any problems with
programming using command bars... :)
http://pix.academ.org/img/2008/09/15/680b0138b74d561348a2d0675397132f

As for UIObject model, I also thought it is a "silver bullet" until
discovered a "fatal flaw" (sic!) in it... Unfortunately I am still
unable to overcome that issue (see the very last post to the following
thread for detailed info). So beware! (though this issue that turned
out to be "fatal" for me might be of no importance for the majority of
developers)...
http://groups.google.com/group/micr...veloper/browse_thread/thread/ba9a0265afc1541b

Kind regards, Nikolay.

SomeNewDev:
Hello,

yesterday I saw this webcast about 'Visio 2007 for developers' by Senaj Lelic.
It was recommended _NOT_ to use the CommandBars in Visio add-ins coz of bugs.
And yes, seems I've already noticed them acting wild sometimes.

So I switched to Visio's ToolbarItems and MenuItems collections.
Adding them works ok so far. But it was NOT shown how to add events
to their items, and I still can't figure it out.

Well, in the SDK only CommandBars are used... nowhere to look it up then :?

Could somebody post a snippet please ?
Thanks.

PS: This is what I've got so far:

[...]
Visio.UIObject VisioUIO;
Visio.MenuSet CurrentVisioMenuSet;
Visio.Menu FMVisioMenu;
Visio.MenuItems menuItems;
Visio.MenuItem menuItem;

VisioApp = Application;

if (Application.CustomMenus != null)
VisioUIO = Application.CustomMenus;
else
VisioUIO = Application.BuiltInMenus;

CurrentVisioMenuSet = VisioUIO.MenuSets.get_ItemAtID(
(int)Visio.VisUIObjSets.visUIObjSetDrawing);

FMVisioMenu = CurrentVisioMenuSet.Menus.AddAt(8);
FMVisioMenu.Caption = "&My Menu";
menuItems = FMVisioMenu.MenuItems;
menuItem = menuItems.Add();
menuItem.Caption = "&Start";

VisioApp.SetCustomMenus(VisioUIO);
[...]
 
P

Paul Herber

Hi,

ah, then it is possible ! But that's exactly where I'm still stuck.
I tried everything possible to set into this AddOnName.
For instance if I want it to call 'MyProcedure'.. what exactly
would I need to put into AddOnName ??? That's why I was asking,
if somebody would be so kind to post a snippet, coz I couldn't
get it working that way !

[...]
menuItem = menuItems.Add();
menuItem.Caption = "&Start";
menuItem.AddOnName = "MyProcedure";
[...]
MyProcedure()
{
}
[...]

So the current situation is following:
My menu entry + menu item is visible and activated, but
whenever I fill any value into AddOnName, then the menuitem
is deactivated ! So I guess I never found a valid value to fill
into AddOnName. And I also tried it with namespace + class name.
Also with or without parameters.

Please could somebody post these 3 lines of snippet for dummies ! :--)

Here's the official example
http://support.microsoft.com/kb/278534

I have a sample in Delphi at
http://www.delphi-code.sandrila.co.uk/visio/add_menu.php

and there are more samples in the Visio SDK
 

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