Customizing Visio menu?

N

Nikolay Belyh

Sorry, the previous message seems to get cut. Please ignore it.

Here is my problem.
IF there already is a custom visio ui when I try to install my ui,
then some of my menu items do not appear.

Namelly, all items that are being added under my own (top-level) menu
are added normally, but all items that are added under Visio's
"native" menus are for some reason not made visible in Visio UI. This
happens only when I install my menu items into existing custom menu
(added either by user or by other add-in).

All menus are added using "native" ui customization interface, i.e.
"command bars" interfrace is not used.

Application.CustomMenus.UpdateUI is called.

Any help?
Kind regards, Nikolay.
 
P

Paul Herber

Sorry, the previous message seems to get cut. Please ignore it.

Here is my problem.
IF there already is a custom visio ui when I try to install my ui,
then some of my menu items do not appear.

Namelly, all items that are being added under my own (top-level) menu
are added normally, but all items that are added under Visio's
"native" menus are for some reason not made visible in Visio UI. This
happens only when I install my menu items into existing custom menu
(added either by user or by other add-in).

All menus are added using "native" ui customization interface, i.e.
"command bars" interfrace is not used.

Application.CustomMenus.UpdateUI is called.

There are a few (3 that I know of) addons that don't follow the rules
and prevent other addons from adding items to the main menu.
There is nothing your code can do to get around this.
 
N

Nikolay Belyh

I know 2 of them; these are UML addon, Database addon.
But actually this is not the thing I am talking about.

My issue is that when I add menu item under MY menu, it function
properly.
But when I add item under VISIO's menu, it is just not shown..

And the above happens only if the menu has been pre-customized by
another addon.
If I take original visio menu (builtin menu) and applying the
customization to that menu,
everything works perfectly.
 
J

John Goldsmith \(Visio MVP\)

Hello Nikolay,

I think Paul's right although my experience was that I wasn't able to pin it
down to a particular add-in or 'on' (I think I'd disabled pretty much
everything, but still no luck).

Not much help I'm afraid, but I can confirm the behaviour you're seeing as
these are exactly the symptoms I came across a year ago or so.

Are you building a document specific solution or might the CommandBars model
help instead?

Best regards

John


John Goldsmith (Visio MVP)
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
P

Paul Herber

I know 2 of them; these are UML addon, Database addon.
But actually this is not the thing I am talking about.

My issue is that when I add menu item under MY menu, it function
properly.
But when I add item under VISIO's menu, it is just not shown..

And the above happens only if the menu has been pre-customized by
another addon.
If I take original visio menu (builtin menu) and applying the
customization to that menu,
everything works perfectly.

Odd, I've got at least 3 of my own add-ons all running at the same
time, 2 add their own top-level menu and one adds itself to the File
menu.
And they all work in conjunction with the better behaved add-ons,
Plan, Org-Chart etc.
I have had reports stating that the menus don't appear, but then
suddenly start working 2 days later and the continue to do so. I put
that down to the add-on cache not being updated but have no further
evidence of that.

However, I do a few tricks when creating menus, I've included a
complete procedure here (in Delphi but that shouldn't matter - I do
wish Graham Wideman would update his Delphi Visio framework) for
adding a menu with submenu to the File menu.



procedure add_menus(bEnableEvents: boolean);
var
UIObj: Visio_TLB.UIObject;
menusObj: Visio_TLB.Menus;
menuObj: Visio_TLB.Menu;
menuItemObj: Visio_TLB.MenuItem;
visioMenuItemObj: Visio_TLB.MenuItem;
ready: boolean;
i: smallint;
messages: TStringList;
msgDlg: TSimpleForm;
dlgTxt: string;
begin
messages := TStringList.Create;
//messages.Add('Started setting menus.');
try
//MessageDlg('Getting UIObj', mtInformation, [mbOk], 0); // debug
// wait for any startup dialogs to finish
ready := false;
while (ready = false) do
begin
try
if Visio_Controller.Application.BuiltInMenus <> nil then
ready := true;
Forms.Application.ProcessMessages;
except;
end;
end;
sleep(random(3000));
try
UIObj := Visio_Controller.Application.CustomMenus;
if UIObj = nil then
UIObj := Visio_Controller.Application.BuiltInMenus;
except
UIObj := Visio_Controller.Application.BuiltInMenus;
end;
try
Visio_Controller.Application.SetCustomMenus(UIObj);
//MessageDlg('Getting menusObj', mtInformation, [mbOk], 0); //
debug
menusObj := UIObj.MenuSets.ItemAtID[visUIObjSetDrawing].Menus;
//MessageDlg('Getting menuObj', mtInformation, [mbOk], 0); //
debug
menuObj := menusObj.Item[0];
i := menuObj.MenuItems.Count - 1;
if menuObj.MenuItems.Item[i-1].Caption = scMenuRecentStencils then
begin
messages.Free;
exit; // already exists
end;
visioMenuItemObj := menuObj.MenuItems.AddAt(i);
visioMenuItemObj.Caption := scMenuRecentStencils;
Visio_Controller.Application.SetCustomMenus(UIObj);
Visio_Controller.Application.CustomMenus.UpdateUI;
except;
end;

//MessageDlg('Getting menuItemObj', mtInformation, [mbOk], 0); //
debug
//MessageDlg('Setting caption', mtInformation, [mbOk], 0); // debug

try
// Most recently used Stencils menu
menuItemObj := visioMenuItemObj.MenuItems.Add;
menuItemObj.Caption := scMenuMostRecentStencils;
menuItemObj.AddOnName := scMenuMostRecentStencilsVRSAddOn;
menuItemObj.ActionText := scMenuMostRecentStencils;
menuItemObj.MiniHelp := scMenuMostRecentStencils;

{$IFDEF bMyTestingMode}
// remove registration menu
menuItemObj := visioMenuItemObj.MenuItems.Add;
menuItemObj.Caption := scMenuRemoveRegistration;
menuItemObj.AddOnName := scMenuRemoveRegistrationVRSAddOn;
menuItemObj.ActionText := scMenuRemoveRegistration;
menuItemObj.MiniHelp := scMenuRemoveRegistration;
{$ENDIF}

// check for updates menu
menuItemObj := visioMenuItemObj.MenuItems.Add;
menuItemObj.Caption := scMenuVRSCheckForUpdates;
menuItemObj.AddOnName := scMenuCheckUpdateVRSAddOn;
menuItemObj.ActionText := scMenuVRSCheckForUpdates;
menuItemObj.MiniHelp := scMenuVRSCheckForUpdates;

// enter registration key menu
menuItemObj := visioMenuItemObj.MenuItems.Add;
menuItemObj.Caption := scMenuEnterRegistrationKey;
menuItemObj.AddOnName := scMenuEnterRegistrationKeyVRSAddOn;
menuItemObj.ActionText := scMenuEnterRegistrationKey;
menuItemObj.MiniHelp := scMenuEnterRegistrationKey;

// help menu
menuItemObj := visioMenuItemObj.MenuItems.Add;
menuItemObj.Caption := scMenuVSUHelp;
menuItemObj.AddOnName := scMenuHelpVRSAddOn;
menuItemObj.ActionText := scMenuVSUHelp;
menuItemObj.MiniHelp := scMenuVSUHelp;

// about menu
menuItemObj := visioMenuItemObj.MenuItems.Add;
menuItemObj.Caption := scMenuVRSAbout;
menuItemObj.AddOnName := scMenuVSUAboutVRSAddOn;
menuItemObj.ActionText := scMenuVRSAbout;
menuItemObj.MiniHelp := scMenuVRSAbout;

Visio_Controller.Application.SetCustomMenus(UIObj);
Visio_Controller.Application.CustomMenus.UpdateUI;
except;
end;
//messages.Add('Finished setting menus.');
except
//messages.Add(scExceptionInSettingMenus);
end;
dlgTxt := '';
for i := 0 to messages.Count-1 do
begin
if messages.count > 1 then
dlgTxt := dlgTxt + fStr(i+1) + '. ' + messages.Strings +
sCRLF
else
dlgTxt := dlgTxt + messages.Strings + sCRLF;
end;
waitingForForm := false;
if dlgTxt <> '' then
begin
waitingForForm := true;
try
msgDlg := TSimpleForm.Create(Forms.Application);
msgDlg.SetText(dlgTxt);
msgDlg.Show;
except;
end;
end;
messages.Free;
// wait for dialog to be closed
while (waitingForForm = true) do
begin
try
Forms.Application.ProcessMessages;
except;
end;
end;
if bEnableEvents then
enableEvents();
end;
 
N

Nikolay Belyh

Paul, many thanks, I'll try that.

Well, actually I knew that issue with "menu not appearing in UI" can
be sometimes cured by changing ConfigChangeID (or how do you call
that) registry key, but I'm definitely having some other issue. I
mean, my addon runs, adds all menus, and I can enumerate all my items
using Visio API. According to API, all items are in place, visible and
enabled. I mean, if I iterate through menu items, all items I have
added are presented. BUT only items that were added under MY top-level
menu are actually visible. "UpdateUI" does not help. The items added
under visio's native menus are just not visible. That is the issue I'm
fighting against..

And the above happens ONLY if the visio menu has been pre-customized
by other addin. I.e. this happens if I do menu customization from
(already customized by another addon) Application.CustomMenus.

Kind regards, Nikolay.
 
P

Paul Herber

Paul, many thanks, I'll try that.

Well, actually I knew that issue with "menu not appearing in UI" can
be sometimes cured by changing ConfigChangeID (or how do you call
that) registry key, but I'm definitely having some other issue. I
mean, my addon runs, adds all menus, and I can enumerate all my items
using Visio API. According to API, all items are in place, visible and
enabled. I mean, if I iterate through menu items, all items I have
added are presented. BUT only items that were added under MY top-level
menu are actually visible. "UpdateUI" does not help. The items added
under visio's native menus are just not visible. That is the issue I'm
fighting against..

And the above happens ONLY if the visio menu has been pre-customized
by other addin. I.e. this happens if I do menu customization from
(already customized by another addon) Application.CustomMenus.

Do you want to post your code? Or email it to me?
 
N

Nikolay Belyh

It seems that I have found out the conditions under which it does not
work (is it a bug??). You cannot add menu items to the LAST visio
menu. That is, you can't add items to "Help" menu. You can add items
to any menu but the last one. Also you cannot add items to a "context"
custom menu (probably for the same reason, since it has only one item
- i.e. the "last" one). I mean, I can't add items to
"visUIObjSetCntx_DrawObjSel" menu as well. All of the above is true if
the menu has been pre-customized, i.e. if I start from the custom
menu.

----- the sample code -----

Set cm = Application.CustomMenus
Set mnus = cm.MenuSets.ItemAtID(2).Menus
Set mi = mnus(0).MenuItems.Add
mi.Caption = "This works"
Application.CustomMenus = cm
Application.CustomMenus.UpdateUI

Set cm = Application.CustomMenus
Set mnus = cm.MenuSets.ItemAtID(2).Menus
Set mi = mnus(mnus.Count - 2).MenuItems.Add
mi.Caption = "This also works"
Application.CustomMenus = cm
Application.CustomMenus.UpdateUI

Set cm = Application.CustomMenus
Set mnus = cm.MenuSets.ItemAtID(2).Menus
Set mi = mnus(mnus.Count - 1).MenuItems.Add
mi.Caption = "This does not work"
Application.CustomMenus = cm
Application.CustomMenus.UpdateUI
 
N

Nikolay Belyh


You can add to help menu normally; I know that:

http://pix.academ.org/img/2008/08/04/55ba99d308a6c9b38a9af90e5439c759

All of the above weird stuff happens only if you try installing your
menu into menu that has been already pre-cusotmized by another
"external" addon (and that is not UML or Database addon, just third-
party addon). I.e. if the menu has been already pre-customized by
addon that is not located in your own DLL (I belive).

Kind regards, Nikoay.
 
P

Paul Herber

You can add to help menu normally; I know that:

http://pix.academ.org/img/2008/08/04/55ba99d308a6c9b38a9af90e5439c759

All of the above weird stuff happens only if you try installing your
menu into menu that has been already pre-cusotmized by another
"external" addon (and that is not UML or Database addon, just third-
party addon). I.e. if the menu has been already pre-customized by
addon that is not located in your own DLL (I belive).

Kind regards, Nikoay.

I shall try that tomorrow.
So, if you write an addon that adds a menu to the File menu, then try
my http://www.visio-recent-stencils.sandrila.co.uk/ which also
modifies the File menu. Would that prove the effect?
 

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