|
Support
ActiveX / COM
Visual C++ / MFC
Customer Spotlight
Corporate Partners
Contact Sales
Call center available M-F 9:00 - 6:00 US Eastern Time. U.S. and Canada International Email |
Using Commandbar Actions
Author: Mike Palmatier
Posted: August 1, 2006
Environment: Visual Basic 6.0
CommandBar Actions eliminate the need to use the Update event to update\change the state and properties of
an item that appears multiple places in your menus and toolbars. For example, you might have a menu item
that also appears in a toolbar, then a user might have created the same button and placed it in a user
created toolbar. With Actions you can simply modify the action for the item and it will update all
occurences of the item, no matter how many a user might have added.
'Constants used to identify controls Const ID_FILE_NEW = 100 Const ID_FILE_OPEN = 101 Const ID_FILE_CLOSE = 102 Const ID_FILE_SAVE = 103 Const ID_FILE_EXIT = 104 Const ID_FILE_PRINT = 113 Const ID_FILE_PRINT_SETUP = 114
Private Sub Form_Load()
'Enable the use of actions CommandBars.EnableActions
'Create Actions to be used by CommandBar items. You can create 'the action before or after the CommandBar Items are added, but 'if you create them before like this sample be sure not to 'overwrite any of the 5 properties of the actions when the 'CommandBar item is added. CommandBars.Actions.Add ID_FILE_NEW, "&New", "New", _ "Create a new document", "File" CommandBars.Actions.Add ID_FILE_OPEN, "&Open", "Open", _ "Open an existing document", "File" CommandBars.Actions.Add ID_FILE_SAVE, "&Save", "Save", _ "Save the active document", "File" CommandBars.Actions.Add ID_FILE_PRINT, "&Print", "Print", _ "Print the active document", "File" CommandBars.Actions.Add ID_FILE_PRINT_SETUP, "&Print Setup", _ "Print Setup", "Change the printing options", "File" CommandBars.Actions.Add ID_FILE_CLOSE, "&Close", "Close", _ "Close the active document", "File" CommandBars.Actions.Add ID_FILE_EXIT, "&Exit", "Exit", _ "Quit the application; prompts to save documents", "File"
Dim Control As CommandBarControl Dim ControlFile As CommandBarPopup
'Add some CommandBar items. Set ControlFile = CommandBars.ActiveMenuBar.Controls.Add( _ xtpControlPopup, 0, "&File") With ControlFile.CommandBar.Controls .Add xtpControlButton, ID_FILE_NEW, "" .Add xtpControlButton, ID_FILE_OPEN, "" .Add xtpControlButton, ID_FILE_SAVE, "" Set Control = .Add(xtpControlButton, ID_FILE_PRINT, "") Control.BeginGroup = True .Add xtpControlButton, ID_FILE_PRINT_SETUP, "" Set Control = .Add(xtpControlButton, ID_FILE_EXIT, "") Control.BeginGroup = True End With
Dim ToolBar As CommandBar Set ToolBar = CommandBars.Add("Standard", xtpBarTop) With ToolBar.Controls .Add xtpControlButton, ID_FILE_NEW, "" .Add xtpControlButton, ID_FILE_OPEN, "" .Add xtpControlButton, ID_FILE_SAVE, "" Set Control = .Add(xtpControlButton, ID_FILE_PRINT, "") Control.BeginGroup = True End With
'Disable ALL items with Id ID_FILE_SAVE CommandBars.Actions(ID_FILE_SAVE).Enabled = False
'Change the Caption of ALL items with Id ID_FILE_PRINT CommandBars.Actions(ID_FILE_PRINT).Caption = _ "Print Document"
'Change the ToolTipText of ALL items with Id ID_FILE_OPEN CommandBars.Actions(ID_FILE_OPEN).ToolTipText = _ "Open an existing document" End Sub |
