Building the Smart Tag Action
Now that you recognize the terms, you need to build the actions. The code for the Action class is shown in Listing 4
Again, use the attributes necessary for COM Interop. Make sure to generate a different GUID
for the Action class. The properties for the Action class are similar to those found in the Recognizer class.
The Action class uses verbs corresponding with the menu options you define to be displayed in the on-application menu. The VerbCount property defines how many verbs your Action class supports.
Because you are only supporting one smart tag in this example, the VerbID property just returns the VerbIndex. The ShowSmartTagIndicator property defines whether the recognized terms are underlined, like regular smart tags. In most cases you'll want this, so return True for this property.
The VerbCaptionFromID property is called one time for each verb you are supporting: six, in this case. It takes a VerbID as a parameter, which is used in the CASE statement to build the cascading menu.
Now take a look at the InvokeVerb2 method. In the example, you collect information gathered in the Recognizer class along with the VerbID and Application Name, and you display a message box with this information.
Now you can compile the DLL. Before you test it, you must first register the two classes with the Office 2003 smart tag infrastructure so that the Office 2003 applications will know to use the smart tag.
Registering Smart Tag Classes
There are two ways to register your smart tag classes with the smart tag infrastructure. One way is to manually add keys to the HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Smart Tag registry key. There is a key for Recognizers and a key for Actions. You need to add a new key to each section for the appropriate class using the GUIDs specified in the class attributes in your code. Make sure to add the curly brackets back to the GUIDs in these keys.
The second way to do this is to add code that uses reflection to your classes in order to register the smart tag at the same time the smart tag is registered with COM. This is the preferred method, especially if you will be distributing your smart tags. But it takes a bit of code to do it. To see how this is done, refer to the Technical Article on MSDN, "Building Smart Tags in Microsoft Visual Basic .NET," by J Sawyer.
Smart tags have been improved quite a bit in Office 2003. And more Office 2003 applications support smart tags than in Office XP. Developers get new flexibility in creating smart tags using MOSTL combined with regular expressions to define Recognizers. You also get a lot of power developing smart tags in VB.NET or C# with the new version of the Smart Tags 2.0 Type Library.