AddCommand Method
Home Page (Objects) | Overview | FAQ | Reference
Applies to: Application object
Adds a command defined by an add-in to Developer Studio.
Syntax
object**.AddCommand(command_string,method_name,bitmap_offset,cookie)**
Parameters
object
An expression that evaluates to an Application object. When you use the AddCommand method of the Application object, you can omit object because the name of the Application object is implied when you access its properties and methods.
command_string
A String that contains substrings separated by a newline character ('\n'), which is "Chr(10)" in Visual Basic. In order, the substrings are:
Name of the command
This is the command you want to add. If this command conflicts with an existing command, Developer Studio returns False, keeps the existing command, and does not add this command. To prevent conflicts with Developer Studio commands, the add-in should prefix this command with the name of the add-in.
Text displayed on the toolbar button for the command
If you create a toolbar button for carrying out the command, this is the text that goes on the button.
Status bar string
This is the string displayed on the status bar or in the Customize dialog box when the user selects this command.
Tooltip string
This is the string displayed in the tooltip when the user holds the mouse pointer over the toolbar button assigned to the command.
Note Even if the add-in does not provide a toolbar button for a command, the add-in must provide all four substrings, because users can create toolbar buttons for commands added by add-ins.
method_name
A String that represents the method exposed by the add-in to implement the command.
bitmap_offset
A Long that is the zero - based index into the medium and large command bar button bitmaps for this button image. For example, 0 (zero) represents the first image, 1 represents the second image, and so on. If the add-in does not provide a default image for toolbar buttons assigned to this command, the value of bitmap_offset is -1.
cookie
A Long that is the identifier of the add-in. Developer Studio passes this value to the add-in through the add-in's OnConnection method.
Return Values
The AddCommand method returns one of the following values:
True The command was added.
False The command was not added because its name conflicted with the name of an existing command.
Remarks
Only add-ins can call the AddCommand method. VBScript macros cannot.
Example
The following example, written in Visual C++, is the code automatically generated when you create an add-in using the Developer Studio Add-in Wizard:
VARIANT_BOOL bRet;
pApplication->AddCommand(bszCmdString, bszMethod, 0, m_dwCookie, &bRet);
if (bRet == VARIANT_FALSE)
{
*OnConnection = VARIANT_FALSE;
return S_OK;
}
See Also AddcommandBarButton method, AddKeyBinding method, Adding Commands to Developer Studio, EnableModeless method, SetAddInInfo method.