Creating and Using Annotations (C++ Builder 6.0)
Note: |
This topic is for Document/Medical only. |
Take the following steps to add code that demonstrates the creation and deletion, saving and loading, and copying and pasting of annotation objects. This code also demonstrates the related events. Message boxes prompt for user actions that trigger events.
1. |
Start with the project that you created in Loading and Displaying an Image. |
2. |
On the Project pull-down menu, use the Import Type library… and install the LEAD Raster Annotation Library (14.5 Press OK. |
3. |
Select LEAD Raster Annotation, from ActiveX tab and add it to your form. |
4. |
Declare the following variable in the private section of “Unit1.h”. |
int NewTag;
5. |
Add the following code to the btnLoadImage click’s procedure. |
//Unlock annotation support LEADRasterView1->Raster->UnlockSupport (L_SUPPORT_DOCUMENT, AnsiToOLESTR("TestKey"));
//Connect the raster annotation object to the RasterView control
LEADRasterAnnotation1->set_AnnParentRasterView ( LEADRasterView1->Raster );
//Enable left button drawing of annotations
LEADRasterAnnotation1->set_AnnAutoDrawEnable ( true );
//Enable right-click to display annotation menus
LEADRasterAnnotation1->set_AnnAutoMenuEnable ( true );
6. |
At the top of your main form, add four buttons and name them as follows: |
|
|
Name |
Caption |
|
btnAnnToggle |
Start |
|
btnIOToggle |
Save |
|
btnClipboardToggle |
Copy |
|
btnRealize |
Realize |
7. |
Code the btnAnnToggle control's Click procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
void __fastcall TForm1::btnAnnToggleClick(TObject *Sender)
{
//Use the button to toggle between design mode and run mode
if (btnAnnToggle->Caption == "Start")
{
LEADRasterAnnotation1->set_AnnUserMode ( ANN_USERMODE_DESIGN );
LEADRasterAnnotation1->set_AnnTool ( ANN_TOOL_BUTTON ) ;
//Make run mode the next thing.
btnAnnToggle->Caption= "Run Mode";
ShowMessage ("In design mode now. Draw a button object.");
}
else
{
if (btnAnnToggle->Caption == "Design Mode")
{
LEADRasterAnnotation1->set_AnnUserMode ( ANN_USERMODE_DESIGN );
LEADRasterAnnotation1->set_AnnTool ( ANN_TOOL_BUTTON );
//Make run mode the next thing.
btnAnnToggle->Caption= "Run Mode";
}
else //The button takes us to run mode
{
LEADRasterAnnotation1->set_AnnUserMode ( ANN_USERMODE_RUN );
ShowMessage ("Click on your new button");
btnAnnToggle->Caption= "Design Mode";
}
}
}
8. |
Code the btnIOToggle control's Click procedure as follows: |
void __fastcall TForm1::btnIOToggleClick(TObject *Sender)
{
int nRet;
//Disable errors so that we can trap our own.
LEADRasterAnnotation1->set_EnableMethodErrors (false);
//Use the button to toggle between saving and loading annotations
if (btnIOToggle->Caption == "Save")
{
//Do nothing if there are no annotations.
if (LEADRasterAnnotation1->AnnContainer == 0)
return;
//Save the all annotations.
nRet = LEADRasterAnnotation1->AnnSave (AnsiToOLESTR("c:\\temp\\tmp.ann"), ANN_FMT_NATIVE, false, SAVE_OVERWRITE, 1);
if (nRet == 0)
{
btnIOToggle->Caption = "Load";
ShowMessage ("Use the right mouse button to delete any annotations, then click Load");
}
else
ShowMessage ("Error code: " + IntToStr(nRet));
}
else
{
//We are loading annotations
//Make sure we are in design mode
LEADRasterAnnotation1->set_AnnUserMode ( ANN_USERMODE_DESIGN );
//Load the annotations.
nRet = LEADRasterAnnotation1->AnnLoad (AnsiToOLESTR("c:\\temp\\tmp.ann"), 1);
if (nRet == 0)
btnIOToggle->Caption = "Save";
else
ShowMessage ("No annotations to load");
}
}
9. |
Code the btnClipboardToggle control's Click procedure as follows. (Note that Copy, Cut, and Paste are available as automated popup menu options. This code is for tailoring your application.) |
void __fastcall TForm1::btnClipboardToggleClick(TObject *Sender)
{
int nRet;
//Disable errors so that we can trap our own.
LEADRasterAnnotation1->set_EnableMethodErrors ( false ) ;
//Use the button to toggle between copying and pasting annotations
if (btnClipboardToggle->Caption == "Copy")
{
//Do nothing if there are no annotations.
if (LEADRasterAnnotation1->AnnContainer == 0)
return;
//Copy all annotations to the clipboard.
nRet = LEADRasterAnnotation1->AnnCopy (ANN_FMT_NATIVE, false, true);
if (nRet == 0)
{
//Make pasting the next thing.
btnClipboardToggle->Caption = "Paste";
ShowMessage ("Use the right mouse button to delete any annotations, then click Paste");
}
else
ShowMessage ("Error code: " + IntToStr(nRet));
}
else //We are pasting annotations
{
//Make sure we are in design mode
LEADRasterAnnotation1->set_AnnUserMode ( ANN_USERMODE_DESIGN );
//Paste the annotations
if (LEADRasterAnnotation1->AnnPasteReady)
{
LEADRasterAnnotation1->AnnPaste ();
btnClipboardToggle->Caption = "Copy";
}
else
ShowMessage ("No annotations to paste");
}
}
10. |
Code the Realize control's Click procedure (which renders the annotation objects to the bitmap) as follows: |
void __fastcall TForm1::btnRealizeClick(TObject *Sender)
{
LEADRasterAnnotation1->AnnRealize (false);
LEADRasterView1->ForceRepaint ();
ShowMessage ("Annotations are now rendered to the bitmap");
}
11. |
Handle the LEADRasterAnnotation1 OnAnnCreate event, and code LEADRasterAnnotation1AnnCreate procedure as follows: |
void __fastcall TForm1::LEADRasterAnnotation1AnnCreate(TObject *Sender,
long hAnnObject)
{
AnnObjectType ObjectType;
//Update the tag if we need one.
LEADRasterAnnotation1->AnnGetType (hAnnObject);
ObjectType = LEADRasterAnnotation1->AnnType;
if ((ObjectType == ANN_OBJECT_BUTTON) || (ObjectType == ANN_OBJECT_HOTSPOT))
{
NewTag++;
LEADRasterAnnotation1->AnnSetTag (hAnnObject, NewTag);
}
}
12. |
Handle the LEADRasterAnnotation1 OnAnnDestroy event, and code the LEADRasterAnnotation1AnnDestroy procedure as follows: |
void __fastcall TForm1::LEADRasterAnnotation1AnnDestroy(TObject *Sender,
long hAnnObject)
{
long lTag;
LEADRasterAnnotation1->AnnGetTag (hAnnObject);
lTag= LEADRasterAnnotation1->AnnTag;
ShowMessage ("The object tagged " + IntToStr(lTag) + " is deleted.");
}
13. |
Handle the LEADRasterAnnotation1 OnAnnClicked event, and code the LEADRasterAnnotation1AnnClicked procedure as follows: |
void __fastcall TForm1::LEADRasterAnnotation1AnnClicked(TObject *Sender,
long hAnnObject)
{
long lTag;
LEADRasterAnnotation1->AnnGetTag (hAnnObject);
lTag= LEADRasterAnnotation1->AnnTag;
ShowMessage ("This is what we do for the button tagged " + IntToStr(lTag));
}
14. |
Handle the LEADRasterAnnotation1 OnAnnDrawn event, and code the LEADRasterAnnotation1AnnDrawn procedure as follows: |
void __fastcall TForm1::LEADRasterAnnotation1AnnDrawn(TObject *Sender,
long hAnnObject)
{
LEADRasterAnnotation1->set_AnnTool ( ANN_TOOL_SELECT );
ShowMessage ("Use the right mouse button to modify this object; then click on Run Mode to test it.");
}
15. |
Run your program to test it. |