AddCommand Method

Home Page (Objects)OverviewFAQReference

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:

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:

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.