Creating and Using Annotations (Visual Basic Script)
Note: |
This topic is for Document/Medical only. |
Note: |
You’ll need to call the UnlockSupport method to unlock Document Imaging capability. |
Take the following steps to add code that demonstrates the creation and deletion, saving and loading, and copying and pasting of annotation objects:
1. |
Start with the project that you created in Loading and Displaying an Image. |
2. |
Add the following line between the <SCRIPT> and </SCRIPT> tags: |
Dim NewTag
3. |
Add the following code between the <BODY> and </BODY> tags to add the annotations COM object: |
<OBJECT ID="RasterAnn" NAME="RasterAnn"
CLASSID="CLSID:00140723-B1BA-11CE-ABC6-F5B2E79D9E3F"
CODEBASE="path to CAB file/Ltran14n.CAB">
<P>This is not supported in web browser.</P>
</OBJECT><BR>
4. |
Add the following code to the Window_OnLoad() procedure: |
RasterAnn.AnnParentRasterView = LEADRasterView1
'Enable left button drawing of annotations
RasterAnn.AnnAutoDrawEnable = True
'Enable right-click to display annotation menus
RasterAnn.AnnAutoMenuEnable = True
NewTag = 0
5. |
Add the following code between the <FORM> </FORM> tags to create four buttons: |
<INPUT TYPE="button" NAME="btnStart" VALUE="Start" LANGUAGE="VBScript"
OnClick="Start">
<INPUT TYPE="button" NAME="btnSave" VALUE="Save" LANGUAGE="VBScript"
OnClick="Save">
<INPUT TYPE="button" NAME="btnCopy" VALUE="Copy" LANGUAGE="VBScript"
OnClick="Copy">
<INPUT TYPE="button" NAME="btnRealize" VALUE="Realize" LANGUAGE="VBScript"
OnClick="Realize">
6. |
Add the following code between the <SCRIPT> </SCRIPT> tags to for the btnStart button: |
Sub Start()
Dim ANN_USERMODE_DESIGN
Dim ANN_TOOL_BUTTON
Dim ANN_USERMODE_RUN
ANN_USERMODE_DESIGN = 1
ANN_TOOL_BUTTON = 13
ANN_USERMODE_RUN = 2
'Use the button to toggle between design mode and run mode
If LEADForm.btnStart.Value = "Start" Then
RasterAnn.AnnUserMode = ANN_USERMODE_DESIGN
RasterAnn.AnnTool = ANN_TOOL_BUTTON
'Make run mode the next thing.
LEADForm.btnStart.Value = "Run Mode"
MsgBox "In design mode now. Draw a button object."
ElseIf LEADForm.btnStart.Value = "Design Mode" Then
RasterAnn.AnnUserMode = ANN_USERMODE_DESIGN
RasterAnn.AnnTool = ANN_TOOL_BUTTON
'Make run mode the next thing.
LEADForm.btnStart.Value = "Run Mode"
Else 'The button takes us to run mode
RasterAnn.AnnUserMode = ANN_USERMODE_RUN
MsgBox "Click on your new button"
LEADForm.btnStart.Value = "Design Mode"
End If
End Sub
7. |
Add the following code between the <SCRIPT> </SCRIPT> tags to for the btnSave button: |
Sub Save()
Dim nRet
Dim ANN_USERMODE_DESIGN
Dim ANN_FMT_NATIVE
Dim SAVE_OVERWRITE
ANN_USERMODE_DESIGN = 1
ANN_FMT_NATIVE = 0
SAVE_OVERWRITE = 0
'Disable errors so that we can trap our own.
RasterAnn.EnableMethodErrors = False
'Use the button to toggle between saving and loading annotations
If LEADForm.btnSave.Value = "Save" Then
'Do nothing if there are no annotations.
If RasterAnn.AnnContainer = 0 Then Exit Sub
'Save the all annotations.
nRet = RasterAnn.AnnSave("c:\tmp.ann", ANN_FMT_NATIVE, False, SAVE_OVERWRITE, 0)
If nRet = 0 Then
LEADForm.btnSave.Value = "Load"
MsgBox "Use the right mouse button to delete any annotations, then click Load"
Else
MsgBox "Error code: " & CStr(nRet)
End If
Else 'We are loading annotations
'Make sure we are in design mode
RasterAnn.AnnUserMode = ANN_USERMODE_DESIGN
'Load the annotations.
nRet = RasterAnn.AnnLoad("c:\tmp.ann", 1)
If nRet = 0 Then
LEADForm.btnSave.Value = "Save"
Else
MsgBox "No annotations to load"
End If
End If
End If
End Sub
8. |
Add the following code between the <SCRIPT> </SCRIPT> tags to for the btnCopy button: |
Sub Copy()
Dim nRet
Dim ANN_USERMODE_DESIGN
Dim ANN_FMT_NATIVE
ANN_USERMODE_DESIGN = 1
ANN_FMT_NATIVE = 0
'Disable errors so that we can trap our own.
RasterAnn.EnableMethodErrors = False
'Use the button to toggle between copying and pasting annotations
If LEADForm.btnCopy.Value = "Copy" Then
'Do nothing if there are no annotations.
If RasterAnn.AnnContainer = 0 Then Exit Sub
'Copy all annotations to the clipboard.
nRet = RasterAnn.AnnCopy(ANN_FMT_NATIVE, False, True)
If nRet = 0 Then
'Make pasting the next thing.
LEADForm.btnCopy.Value = "Paste"
MsgBox "Use the right mouse button to delete any annotations, then click Paste"
Else
MsgBox "Error code: " + CStr(nRet)
End If
Else 'We are pasting annotations
'Make sure we are in design mode
RasterAnn.AnnUserMode = ANN_USERMODE_DESIGN
'Paste the annotations
If RasterAnn.AnnPasteReady Then
nRet = RasterAnn.AnnPaste
LEADForm.btnCopy.Value = "Copy"
Else
MsgBox "No annotations to paste"
End If
End If
End If
End Sub
9. |
Add the following code between the <SCRIPT> </SCRIPT> tags to for the btnRealize button: |
Sub Realize()
RasterAnn.AnnRealize False
LEADRasterView1.ForceRepaint
MsgBox "Annotations are now rendered to the bitmap"
End Sub
10. |
Add the following code between the <HEAD> </HEAD> tags to for handling the OnAnnCreate, OnAnnDrawn, OnAnnClicked and OnAnnDestroy events respectively: |
<SCRIPT LANGUAGE="VBScript" FOR="RasterAnn" EVENT="OnAnnCreate(hAnnObject)">
<!--
RasterAnn.AnnSetForeColor hAnnObject, RGB(255, 255, 0), False
Dim ANN_OBJECT_BUTTON
Dim ANN_OBJECT_HOTSPOT
ANN_OBJECT_BUTTON = 3
ANN_OBJECT_HOTSPOT = 7
RasterAnn.AnnGetType hAnnObject
If RasterAnn.AnnType = ANN_OBJECT_BUTTON Or RasterAnn.AnnType = ANN_OBJECT_HOTSPOT
Then NewTag = NewTag + 1
RasterAnn.AnnSetTag hAnnObject, NewTag
End If
//-->
</SCRIPT>
<SCRIPT LANGUAGE="VBScript" FOR="RasterAnn" EVENT="OnAnnDrawn(hAnnObject)">
<!--
Dim ANN_TOOL_SELECT
ANN_TOOL_SELECT = 0
RasterAnn.AnnTool = ANN_TOOL_SELECT
MsgBox "Use the right mouse button to modify this object; then click on Run Mode to test it."
//-->
</SCRIPT>
<SCRIPT LANGUAGE="VBScript" FOR="RasterAnn" EVENT="OnAnnClicked(hAnnObject)">
<!--
Dim lTag
RasterAnn.AnnGetTag hAnnObject
LTag = RasterAnn.AnnTag
MsgBox "This is what we do for the button tagged " + CStr(lTag)
//-->
</SCRIPT>
<SCRIPT LANGUAGE="VBScript" FOR="RasterAnn" EVENT="OnAnnDestroy(hAnnObject)">
<!--
Dim lTag
RasterAnn.AnnGetTag hAnnObject
LTag = RasterAnn.AnnTag
MsgBox "The object tagged " + CStr(lTag) + " is deleted."
//-->
</SCRIPT>
11. |
Run your page to test it. |