
Accelerator Key Display in Custom Menu
John,
Yes, now that I look more closely, it appears that you are correct. The DVS
documentation about \a to show accelerator text is obsolete (or it may have
always been incorrect, since it doesn't seem to work at least as far back as
Visio 5.0).
It looks like Visio is supposed to be showing the accelerator text
automatically, but for some reason it isn't showing up until a context
switch occurs. For example, opening the ShapeSheet and then switching back
to the drawing context will cause the accelerator text to display in the
menu. Unfortunately, I don't know of a workaround for this problem.
As for your question about assigning a built-in command to the menu item...
Following on from what I said above, the menu item should display the
accelerator text independently of what the caption is, so changing the
caption won't rid your menu item of the CTRL+P accelerator. Adding an
accelerator to a command doesn't rid the command of the accelerators that
were already assigned to it. If you don't want other accelerators for the
command, then you need to go through the accelerator table and delete the
built-in accelerators that correspond to the print preview command.
--
Dawn
This posting is provided "AS IS" with no warranties, and confers no rights.
Quote:
> I am also looking into this:
> I find that it is linked to the cmdNum
> So the menuitem and the accellkey must share the same cmdnum? If I assign
a
> new menuitem the cmdnum 1010 fileprint, then I see "menuitem CTRL+P"
> even when I state thate the menuitem caption is "menuitem". I find the
> "Open... \a CTRL+0" does not work.
> > Michael,
> > If you would like the accelerator keys to appear in the menu, you need
to
> > explicitly specify this in the caption. Here is the information from
the
> > DVS documentation
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devr...
Quote:
> > L/DVS_22_Customizing_the_Visio_UI_620.asp)
> > Caption specifies the text that appears on a menu or menu item. If you
> want
> > to display the accelerator with the menu item, include it as part of the
> > Caption property's text and insert two spaces between the "\a" and the
> > accelerator text. For example:
> > "Open...\a CTRL+O"
> > In this example, "Open..." is the menu item's caption; "CTRL+O" is the
> > accelerator text; and "\a" left justifies the accelerator text. Adding
the
> > accelerator text to the Caption property doesn't add an accelerator, it
> > simply displays it as part of the caption. You add accelerators by using
> the
> > accelerator objects in the Visio object model.
> > --
> > Dawn
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> > > How do you get the accelerator keys to appear in custom menu items? I
> can
> > > add the menu item and the accelerator with both working properly, but
> > there
> > > is no visual clue as to the presence of the accelerator. For example,
> if
> > > you paste the following code in the ThisDocument class module you can
> > > observe what I'm talking about:
> > > Sub SetupUI()
> > > Dim UI As UIObject
> > > Set UI = Application.BuiltInMenus
> > > Dim MI As MenuItem
> > > Set MI =
> UI.MenuSets.ItemAtID(visUIObjSetDrawing).Menus.Item(0).MenuItems.AddAt(0)
> > > MI.Caption = "My Addon Function"
> > > MI.Enabled = True
> > > MI.FaceID = visIconIXCUSTOM_CARDS
> > > MI.AddOnName = "ThisDocument.MyFunc"
> > > Dim AI As AccelItem, AIC As AccelItems
> > > Set AIC = UI.AccelTables.ItemAtID(visUIObjSetDrawing).AccelItems
> > > Set AI = AIC.Add
> > > AI.AddOnArgs = MI.AddOnArgs
> > > AI.AddOnName = MI.AddOnName
> > > AI.Alt = 0
> > > AI.CmdNum = MI.CmdNum
> > > AI.Control = True
> > > AI.Key = 77
> > > AI.Shift = 0
> > > Application.SetCustomMenus UI
> > > UI.UpdateUI
> > > End Sub
> > > Sub MyFunc()
> > > MsgBox "In MyFunc"
> > > End Sub
> > > If you run SetupUI to setup the menu and accelerator, you will see
that
> > the
> > > menu item appears as the first item in the file menu. However, no
> > > accelerator is shown even though CTRL-M works as an accelerator
calling
> > the
> > > ThisDocument.MyFunc function.
> > > Thanks,
> > > Michael