Thêm tính năng cho một Add-In Khi thực hiện các chức năng của một Add-In, bạn sẽ được quan tâm nhất với thu giữ các cuộc gọi đến Exec, mà VS cuộc gọi bất cứ khi nào người sử dụng chọn trình đơn Tools mục cho bạn Add-In. Phần này cũng sẽ bao gồm một vài phương pháp khác: OnConnection, trong đó có chứa rất nhiều mã khởi tạo, và QueryStatus, đó là thuận tiện cho việc quản lý nhà nước của các Add-Trong mục trình đơn. Chúng tôi sẽ xem xét OnConnection đầu tiên để bạn có thể xem như. | Chapter 13 Extending Visual Studio 2010 383 summary Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked. summary param term commandName The name of the command to execute. param param term executeOption Describes how the command should be run. param param term varIn Parameters passed from the caller to the command handler. param param term varOut Parameters passed from the command handler to the caller. param param term handled Informs the caller if the command was handled or not. param seealso class Exec public void Exec string commandName vsCommandExecOption executeoption ref object varIn ref object varOut ref bool handled private DTE2 _applicationObject private AddIn _addInInstance You ve had an overview of what the IDTExtensibility2 and IDTCommandTarget interfaces do and reviewed the comments in Listing 13-1. In the next section you ll see how to add your own code to the interface methods to make the KeystrokeFinder Add-In perform some useful work. Adding Functionality to an Add-In When implementing the functionality of an Add-In you ll be most concerned with capturing the call to Exec which VS calls whenever the user selects the Tools menu item for your Add-In. This section will also cover a couple of other methods OnConnection which contains a lot of initialization code and QueryStatus which is handy for managing the state of the Add-In menu item. We ll look at OnConnection first so that you can see how the Add-In is initialized. 384 Microsoft Visual Studio 2010 A Beginner s Guide Reviewing the OnConnection Method As you learned earlier the Connect class implements various interface methods so that VS can call into those methods to run your Add-In. One of the primary methods is OnConnection which is a member of the IDTExtensibility2 interface. VS calls OnConnection when the Add-In loads. When calling OnConnection VS passes four parameters that you can use to initialize the Add-In. The Add-In Project Wizard