With QuickField 5.1, you can extend its capabilities with add-ins. Add-in is a program or component that adds custom features to QuickField, such as custom menu items, toolbar buttons etc.
In this paper we describe how to create and register your own add-in. We also describe how to create a setup program for your add-in.
There are two types of add-ins in QuickField: COM add-ins and EXE add-ins.
COM add-ins are called from QuickField using COM (OLE Automation). So, COM add-in should be a COM server (either DLL server or EXE server). See How to Write a COM Add-ins below for more details.
With EXE add-ins, it is possible to use any program as an add-in. During the add-in registration, you specify the name of the executable file (may be with parameter), and then, when necessary, QuickField will run this executable file.
To use an add-in, it is necessary to register it in QuickField. During this registration, you should specify the following information:
Add-in type
For COM add-ins, name of the COM class
For EXE add-in, command line to start the executable
User-friendly name for the add-in (optional)
A brief description of the add-in (optional)
Menu items for the add-in. As a rule, only one menu item is specified. However, for more advanced add-ins, you can specify several items.
For each menu item, you should specify the following:
Menu text
Menu to add this item to (File, Edit, Problem, Tools etc.)
Status line to show for this menu item (optional)
You can specify, when this menu item should be available. You can choose one of the following variants: Always, In model editor only, In postprocessor only.
You can specify that this menu item should be added to context (right button) menu also.
You can specify that this menu item should be available from toolbar also.
In this case, you can choose an icon for the toolbar button from the list of predefined icons.
You can specify a shortcut key for this menu item.
For more details about the add-in properties and add-in menu item properties, see articles Add-in Properties dialog box and Add-in Menu Item dialog box in the QuickField help.
You can register an add-in manually (using the QuickField dialog boxes), or programmatically (adding necessary keys to the registry).
To register an add-in manually, click Add-in Manager on the Tools menu. Then click Add and specify the necessary fields in the Add-in Properties dialog box. For more details, see context help for these dialogs.
To register an add-in programmatically, it is necessary to add several keys to the registry. See How to Register an Add-in from Setup Program below for more details about it.
In this section, we discuss how to create a COM add-in. (We do not discuss creating EXE add-ins in this article, just because it is very easy. In fact, any program can be used as an EXE add-in.)
You can create a COM add-in using any programming tool that allows creating a COM server (Visual Basic, Visual C++, Visual C#, Delphi and many other tools.)
In your COM server, you should implement an object with the following methods:
Method OnStart is optional and could be omitted.
This method is called when user tries to perform the add-in action (that is, when user click the menu item, or click the toolbar button, or press the shortcut key for add-in).
OnCommand ( App As QuickField.Application, Menu As String, Flags As Long )
This method is called when add-in is started, immediately before OnCommand method is called for the first time. So it makes sense to put your initialization code here. This method is optional and can be omitted.
OnStart ( App As QuickField.Application )
Let us consider a simple example on how to create a QuickField COM add-in using Visual Basic 6.0.
You should do the following:
Start Visual Basic
Create new ActiveX DLL project (or ActiveX EXE, if you like).
Specify a project name (for example, MyProject).
Rename class Class1 (provide some readable name). In our example, let it be MyAddin.
On the Project menu click References and add the reference to the QuickField 5.1 Object Library.
In the Code window, insert the following lines:
Public Sub OnCommand(app As QuickField.Application, menu As String)
... insert you code here ...
End Sub
Build your program.
Now you should register your add-in in QuickField.
In the QuickField Tools menu click Add-in Manager.
Click the Add button. Add-in Properties dialog box will appear. In this dialog:
Select Simple COM Add-in radio button.
In the Name of the COM object for the add-in box, specify the COM object name.
For our example, you should specify MyProject.MyAddin.
In general, for Visual Basic projects the object name is <project name>.<class name>.
Click Add Item. Add-in Menu Item dialog box will appear.
In this dialog, specify the Menu Text field. For our example, let it be My First Addin.
Note It also makes sense to specify other fields in Add-in Properties and Add-in Menu Item dialog boxes. For more details, see context help.
Click OK several times to close all dialog boxes.
Now the add-in is registered. Click Tools menu, and you will see that the new item My First Add-in was added to it.
If you click My First Add-in, the component you just wrote will be started, and your code will be executed.
To install your add-in, the following operations should be done in your setup program:
Copy your add-in (DLL or EXE file) to the user's disk.
For COM add-in, register it as a COM server.
Add the branch describing the add-in properties to the registry.
Let us consider the last step in more details.
All the properties of an add-in are stored in the registry branch:
HKEY_LOCAL_MACHINE\Software\Tera Analysis\QuickField\AddIns\<name>,
where <name> is:
for COM add-ins - an object name, as specified in the Name of the COM object for the add-in field.
for EXE add-ins - a command line, as specified in the Command line to call the add-in field.
For example, for the sample add-in described above, the branch name will be:
HKEY_LOCAL_MACHINE_USER\Software\Tera Analysis\QuickField\AddIns\MyProject.MyAddin
To add this branch from your setup program, we would recommend the following steps:
At your own computer, register your add-in manually using the Add-in Manager dialog box.
Using Regedit program, find the branch with the add-in settings.
Copy this branch to some .reg file (click Export Registry File in menu Registry in Regedit.)
Use this .reg file in your setup program to add the branch to the registry of the user's computer.