Accelerator Key Display in Custom Menu 
Author Message
 Accelerator Key Display in Custom Menu

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



Mon, 31 Oct 2005 00:40:16 GMT  
 Accelerator Key Display in Custom Menu
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...
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.


Quote:
> 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



Wed, 09 Nov 2005 02:30:59 GMT  
 Accelerator Key Display in Custom Menu
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.



Quote:
> 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)

- Show quoted text -

Quote:
> >     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



Thu, 10 Nov 2005 12:10:32 GMT  
 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...

- Show quoted text -

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



Mon, 14 Nov 2005 05:03:56 GMT  
 Accelerator Key Display in Custom Menu
As far as the update to the menu - it might be linked to forcing a refresh
of both the menu obj and the accelerator table.



Quote:
> 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.



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

- Show quoted text -

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)

- Show quoted text -

Quote:
> > > >     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



Tue, 15 Nov 2005 21:57:11 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Accelerator keys won't display on form load

2. Accelerator keys in menu right aligned or

3. accelerator keys for system tray popup menu not working

4. How to display accelerator text in customised menu items

5. Need Help: Trouble adding a custom menu pick to a custom popup menu in VBA

6. Alt + Key to access custom menu

7. custom Ctrl menu shortcut-keys

8. Displaying Shortcut Key in Menu

9. Word 2000, CommandBars and Accelerator Keys.

10. Accelerator key problem

11. Accelerator key takes 2 tries to open combobox

12. UserForm, CommandButton, Accelerator Key

 

 
Powered by phpBB® Forum Software