Académique Documents
Professionnel Documents
Culture Documents
Number: STN_SS_016
Product: SmartSketch
Version: All
Platform: Win32
Discipline: Programming
Level/Type: Beginner/Code Sample
Prepared By: Stan Thornton
History: 17 Jan 2002 - Original
Technical Information
When working with toolbars and menus using the SmartSketch automation model, it is
sometimes desirable to enable or disable a toolbar or menu command based on the current
state of the application or addin. In order to accomplish this, you have to use the
Application object's EnableCommand method. The method accepts two arguments, the
CommandID as a long and the EnableFlag as a boolean. For built in SmartSketch
commands, the CommandID is a constant that can be obtained from the Command
Constants enum structure. Programmatically added or user added commands, however,
have no corresponding entry in the Command Constants enum structure, so their
commandID must be obtained at run time. You must know the progID of the command in
order for the following example to work. The Visual Basic function below illustrates how to
perform this operation for Toolbar commands.
Page 1 of 2
'
'Needed Variables
Dim objToolbar As SmartSketch.Toolbar
Dim objToolbarControl As SmartSketch.ToolbarControl
Dim blnFound As Boolean
'
'Turn on error handler
On Error GoTo errHandler
'
'Look through the toolbars collection
For Each objToolbar In objApplication.Toolbars
'Look through the toolbar's controls collection
For Each objToolbarControl In objToolbar.Controls
'Is this the right command?
If objToolbarControl.DLLName = strProgID Then
'Enable or Disable
objApplication.EnableCommand(objToolbarControl.ID, blnEnable)
'Set the Found Flag
blnFound = True
'Exit the ToolbarControls Loop
Exit For
End If
Next
'If we found it, exit the Toolbars loop
If blnFound Then Exit For
Next
'Set the return value
EnableToolbarCommand = 0
'Exit
Exit Function
'
errHandler:
'Set the Return error code
EnableToolbarCommand = Err.Number
'Exit
Exit Function
End Function
Page 2 of 2