Вы находитесь на странице: 1из 2
Software Technical Note Title: Enable or Disable Toolbar and Menu commands from VB Abstract: How

Software Technical Note

Title:

Enable or Disable Toolbar and Menu commands from VB

Abstract:

How to programmatically enable or disable toolbar and menu commands.

Document Information:

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

How to enable or disable toolbar and menu commands from VB

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.

Public Function EnableToolbarCommand(objApplication As

SmartSketch.Application, strProgID As String, blnEnable As Boolean)As Integer '*********************************************************************

'

EnableToolbarCommand

'

'

This routine sets the enabled flag for the specified ProgID.

'

'

Inputs: Application object, the ProgID of the command and the Flag.

'

Outputs: 0 (zero) for success, error number for failure.

'

'********************************************************************

' 'Needed Variables Dim objToolbar As SmartSketch.Toolbar Dim objToolbarControl As

'

'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