RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Using Smart Tags in Office 2003 : Page 4

Smart tags in Office 2003 have been improved to make them easier to develop and to address a few limitations that were found in Office XP. You can now create recognizers for smart tag Lists, which are XML documents, by using regular expressions. The Type Library has also been extended for more power when creating smart tags via code.

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.

Dan Jurden is a Senior Application Developer for EPS-Software Corp located in Houston, Texas, and is a Microsoft Certified Professional. He co-authored the book "Creating Visual FoxPro Applications Using Visual FoxExpress" with Bob Archer, published by Hentzenwerke Publishing. Dan also was the technical editor for "CrysDev: A Developer's Guide to Integrating Crystal Reports" also published by Hentzenwerke Publishing. Dan has also authored articles published in CoDe Magazine and Universal Thread Magazine dealing with SQL Server and other topics. Dan has presented topics at the German VFP DevCon, Essential Fox, SQL Server Live!, and GLGDW conferences. He has been developing client-server applications using SQL Server Crystal Reports for over seven years. .
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date