> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OnCommand Method of the ICommandEvents Interface

> OnCommand method of the ICommandEvents Interface in ABBYY FineReader Engine Visual Components on Windows — This method is implemented on the client-side.

This method is implemented on the client-side. It is called by ABBYY FineReader Engine before executing a command in [Image Viewer](/fine-reader/engine/visual-components-reference/imageviewer), [Zoom Viewer](/fine-reader/engine/visual-components-reference/zoomviewer), [Text Editor](/fine-reader/engine/visual-components-reference/texteditor) or [Document Viewer](/fine-reader/engine/visual-components-reference/documentviewer).

See the list of available commands and the ways these commands can be used in each component:

* [Image Viewer commands](/fine-reader/engine/visual-components-reference/imageviewer/image-viewer-commands)
* [Zoom Viewer commands](/fine-reader/engine/visual-components-reference/zoomviewer/zoom-viewer-commands)
* [Document Viewer commands](/fine-reader/engine/visual-components-reference/documentviewer/document-viewer-commands)
* [Text Editor commands](/fine-reader/engine/visual-components-reference/texteditor/text-editor-commands)

The method delivers to the client information on the command which is going to be executed. With the help of this method it is possible to cancel the operation.

## Syntax

### C++

```cpp theme={null}
HRESULT OnCommand(
  MenuItemEnum  MenuItem,
  VARIANT_BOOL* Cancel
);
```

### C\#

```csharp theme={null}
void OnCommand(
  MenuItemEnum MenuItem,
  out bool     Cancel
);
```

### Visual Basic .NET

```vb theme={null}
Sub OnCommand( _
  MenuItem As MenuItemEnum, _
  ByRef Cancel As Boolean _
)
```

## Parameters

MenuItem

\[in] This variable of the [MenuItemEnum](/fine-reader/engine/visual-components-reference/enumerations/menuitemenum) type specifies the command which has been called.

Cancel

\[out] You may set this variable to TRUE to indicate that the process should be terminated. In this case, the command will not be executed.

## Return values

\[C++ only] If this method returns a value other than S\_OK, it indicates that an error occurred on the client-side, and in this case the value of the Cancel parameter is not taken into account.

## Remarks

The client implementation of this method must assure that all exceptions thrown inside the method are caught and handled and no exceptions are propagated outside the method. Propagation of an exception outside the method may lead to unpredictable results (such as program termination).

## See also

[ICommandEvents](/fine-reader/engine/visual-components-reference/supplementary-objects/icommandevents)

[Customizing the Context Menu and Toolbar of a Visual Component](/fine-reader/engine/guided-tour/advanced-techniques/using-gui-elements/customizing-the-context-menu-and-toolbar-of-a-visual-component)
