Implementing an Automated Annotation Program:
Take the following steps to create and run a program that implements automated annotations. Remember, the purpose of the annotation tutorials is to provide you a quick and easy way to generate an annotation program. For more in depth annotation programming, refer to the Annotate demo.
1. |
Create a new directory in the LTWINxxx\EXAMPLES\DLL directory called EZAUTO. |
2. |
Copy everything in the EZFUNC directory into the EZAUTO directory. |
3. |
Compile the project as is and run EZFUNC32.exe to familiarize yourself with the basic program. You can run the exe file from the MS-DOS prompt, or set the image file to load through the Build -> Settings ->Debug->Program Arguments menu. |
4. |
On the Insert menu, select Files into Project. Add the Ltann_n.lib file to the project from the LTWINxxx\LIB directory. |
5. |
Define the following global variables in EZFUNC.C in the EZAUTO directory: |
BITMAPHANDLE LeadBitmap; /* Bitmap handle to hold the loaded image. */
RECT rClientSize; /* RECT for the client area. */
HANNOBJECT hContainer; /* Container annotation object */
HANNOBJECT hAutoObject; /* Automation object */
HWND ToolbarWnd; /* Window for the annotation toolbar */
POINT ToolbarPt; /* Point that positions the toolbar */
6. |
In the MainWndProc in EZFUNC.C add the following declaration: |
ANNRECT ContainerRect; /* Defining rectangle for the container */
7. |
Under WM_CREATE in EZFUNC.C, add the following code before “return (TRUE);” : |
GetClientRect(hWnd, &rClientSize);
/* Specify the point that positions the toolbar */
ToolbarPt.x = 0;
ToolbarPt.y = 0;
/* Create the toolbar and position its top left corner at 0,0 */
L_AnnCreateToolBar(hWnd, &ToolbarPt,
ANNTOOLALIGN_LEFT | ANNTOOLALIGN_TOP, TRUE, &ToolbarWnd, 0, NULL);
/* Create the annotation container, which we will use as the root container */
ContainerRect.left = 0;
ContainerRect.top = 0;
ContainerRect.right = BITMAPWIDTH(&LeadBitmap) -1;
ContainerRect.bottom = BITMAPHEIGHT(&LeadBitmap) - 1;
L_AnnCreateContainer(hWnd, &ContainerRect, TRUE, &hContainer);
/* Set the annotation scalars and offsets, assuming that the display
dimensions are the same as the client area dimensions */
L_AnnSetScalarX(hContainer, (L_DOUBLE) rClientSize.right / BITMAPWIDTH(&LeadBitmap), 0);
L_AnnSetScalarY(hContainer, (L_DOUBLE) rClientSize.bottom / BITMAPHEIGHT(&LeadBitmap), 0);
L_AnnSetOffsetX(hContainer, (L_DOUBLE) 0, 0);
L_AnnSetOffsetY(hContainer, (L_DOUBLE) 0, 0);
/* Create the automation object */
L_AnnCreate(ANNOBJECT_AUTOMATION, &hAutoObject);
/* Assign the automation object to the container */
L_AnnSetAutoContainer(hAutoObject, hContainer);
/* Enable the automation object */
L_AnnSetActiveState(hAutoObject, ANNACTIVE_ENABLED);
/* Set design mode, which allows creation of annotations */
L_AnnSetUserMode(hContainer, ANNUSER_DESIGN);
/* Set the dots per inch for interpreting physical measurements */
L_AnnSetDpiX(hAutoObject, 600, 0);
L_AnnSetDpiY(hAutoObject, 600, 0);
/* Set the number of possible undo actions */
L_AnnSetUndoDepth(hAutoObject, 3);
/* Set the line tool as the initial annotation tool */
L_AnnSetTool(hAutoObject, ANNTOOL_LINE);
L_AnnSetToolBarChecked(ToolbarWnd, ANNTOOL_LINE);
8. |
Code the WM_PAINT option as follows: |
/* Get the handle to the device context */
hdc = BeginPaint (hWnd, &ps);
if (LeadBitmap.Flags.Allocated) /* Do we have an image? */
{
if (hpalPaint) /* If we have a paint palette, select it */
{
hPalette = SelectPalette (hdc, hpalPaint, FALSE);
/* Uncomment this if you do not process WM_QUERYNEWPALETTE */
/* RealizePalette (hdc); */
}
/* Paint the image */
L_PaintDC (hdc,
&LeadBitmap,
&rLeadSource, /* Source rectangle */
NULL, /* Default source clip area */
&rLeadDest, /* Destination rectangle */
&ps.rcPaint, /* Dest clip set by WM_PAINT */
SRCCOPY); /* Normal Paint */
if (hpalPaint) /* Return old palette */
SelectPalette (hdc, hPalette, FALSE);
L_AnnDraw(hdc, &ps.rcPaint, hContainer);
}
EndPaint (hWnd, &ps); /* Return DC */
return (0);
9. |
Add the following case to the switch statement in the MainWndProc procedure: |
case WM_LTANNEVENT:
/* Match the toolbar selection */
if ((int) wParam == LTANNEVENT_TOOLCHECKED)
{
L_AnnSetTool(hAutoObject, (L_UINT) lParam);
}
return(0);
10. |
Add the following line to WM_DESTROY, immediately before “/* Post WM_QUIT to end the application */” : |
L_AnnDestroy(hContainer, ANNFLAG_RECURSE);
11. |
On the Build menu, select Build Ezfunc32.exe. |
12. |
On the Build menu, select Execute Ezfunc32.exe. |
13. |
Save this project to use for testing other annotation code samples and for implementing the Using Automated Annotations in Run Mode tutorial. |