次の方法で共有


Determine command status by using interop assemblies

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

A VSPackage must keep track of the state of the commands it can handle. The environment cannot determine when a command handled within your VSPackage becomes enabled or disabled. It is the responsibility of your VSPackage to inform the environment about command states, for example, the state of general commands such as Cut, Copy, and Paste.

Status notification sources

The environment receives information about commands through the VSPackages' QueryStatus method, which is part of the VSPackage's implementation of the IOleCommandTarget interface. The environment calls the QueryStatus method of the VSPackage under two conditions:

  • When a user opens a main menu or a context menu (by right-clicking), the environment executes the QueryStatus method on all of the commands on that menu to determine their state.

  • When the VSPackage requests that the environment update the current user interface (UI). This update occurs as commands that are currently visible to the user, such as the Cut, Copy, and Paste grouping on the standard toolbar, become enabled and disabled in response to context and user actions.

    Since the shell hosts multiple VSPackages, the shell's performance would unacceptably degrade if it were required to poll each VSPackage to determine command status. Instead, your VSPackage should actively notify the environment when its UI changes at the time of the change. For more information on update notification, see Update the user interface.

Status notification failure

Failure of your VSPackage to notify the environment of a command state change can place the UI in an inconsistent state. Remember that any of your menu or context menu commands can be placed on a toolbar by the user. Therefore, updating the UI only when a menu or context menu opens is not enough.

See also