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.
Create a new directory in the LEADTOOLS23\Examples\FileFormats\CDLL directory called AnnAuto.
Copy everything in the LoadSave directory into the AnnAuto directory.
Compile the project as is and run LoadSave.exe to familiarize yourself with the basic program.
Open the imports.cpp file and make the additions shown in green:
#if defined(WIN64)#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\x64\\Ltkrn_x.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\x64\\Ltdis_x.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\x64\\Ltfil_x.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\x64\\Ltdlgkrn_x.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\x64\\Ltdlgfile_x.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\x64\\Ltann_x.lib")#else#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Ltkrn_u.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Ltdis_u.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Ltfil_u.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Ltdlgkrn_u.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Ltdlgfile_u.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Ltann_u.lib")#endif // #if defined(WIN64)
Define the following global variables in Loadsave.cpp:
HANNOBJECT hContainer = 0; // Container annotation objectHANNOBJECT hAutomation = 0; // Automation objectHWND hWndToolbar = 0; // Window for the annotation toolbar
In Window_OnCreate in LoadSave.cpp, add the following code before "return (TRUE)":
// Create the annotation toolbar and position its top left corner at 0,0POINT ToolbarPt = {0,0};L_AnnCreateToolBar(hWnd, &ToolbarPt, ANNTOOLALIGN_LEFT | ANNTOOLALIGN_TOP, TRUE, &hWndToolbar, 0, NULL);
After the Window_OnCreate function, add the following function:
L_VOID SetupAnnotations(HWND hWnd){// Delete any existing annotation container, automation objectsif(hAutomation){L_AnnSetActiveState(hAutomation, ANNACTIVE_DISABLED);L_AnnDestroy(hAutomation, ANNFLAG_NOINVALIDATE);hAutomation = 0;}if(hContainer){L_AnnDestroy(hContainer, ANNFLAG_NOINVALIDATE);hContainer = 0;}// Create the automation objectL_AnnCreate(ANNOBJECT_AUTOMATION, &hAutomation);// Set the dots per inch for interpreting physical measurementsL_AnnSetDpiX(hAutomation, 600, 0);L_AnnSetDpiY(hAutomation, 600, 0);// Set the number of possible undo actionsL_AnnSetUndoDepth(hAutomation, 3);// Create the annotation container, which we will use as the root containerANNRECT ContainerRect;ContainerRect.left = 0;ContainerRect.top = 0;ContainerRect.right = BITMAPWIDTH(&Data.BitmapHandle) -1;ContainerRect.bottom = BITMAPHEIGHT(&Data.BitmapHandle) - 1;L_AnnCreateContainer(hWnd, &ContainerRect, TRUE, &hContainer);// Set the scalars and offsetsL_AnnSetScalarX(hContainer, 1, 0);L_AnnSetScalarY(hContainer, 1, 0);L_AnnSetOffsetX(hContainer, (L_DOUBLE) 0, 0);L_AnnSetOffsetY(hContainer, (L_DOUBLE) 0, 0);// Assign the automation object to the containerL_AnnSetAutoContainer(hAutomation, hContainer);// Enable the automation objectL_AnnSetActiveState(hAutomation, ANNACTIVE_ENABLED);// Set design mode, which allows creation of annotationsL_AnnSetUserMode(hContainer, ANNUSER_DESIGN);}
In the Window_OnCommand, add a call to SetupAnnotations() (shown in green)
case IDM_OPEN:nRet = Get_OpenFile (hWnd);if (nRet == 2); /* No file was selected for opening, so do nothing. */else if (nRet == SUCCESS){SetupAnnotations(hWnd);FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage);}else{wsprintf (buf, TEXT("Error %d Loading %s"), nRet,(LPTSTR) Data.szFilename);MessageBox (hWnd, buf, TEXT("Error"), MB_OK);}break;
In the Window_OnPaint function, call L_AnnDraw after the call to L_PaintDC
L_AnnDraw(hdc, &ps.rcPaint, hContainer); In the Window_OnDestroy function, add the following immediately before "/* Post WM_QUIT to end the application":
// Cleanup for annotationsL_AnnDestroy(hContainer, ANNFLAG_NOINVALIDATE);L_AnnDestroy(hAutomation, ANNFLAG_NOINVALIDATE);
Add the following case to the switch statement in the MainWndProc procedure:
LRESULT CALLBACK MainWndProc (HWND hWnd, L_UINT Message, WPARAM wParam, LPARAM lParam){switch (Message){HANDLE_MSG (hWnd, WM_CREATE, Window_OnCreate);HANDLE_MSG (hWnd, WM_COMMAND, Window_OnCommand);HANDLE_MSG (hWnd, WM_PALETTECHANGED, Window_OnPaletteChanged);HANDLE_MSG (hWnd, WM_QUERYNEWPALETTE, Window_OnQueryNewPalette);HANDLE_MSG (hWnd, WM_PAINT, Window_OnPaint);HANDLE_MSG (hWnd, WM_DESTROY, Window_OnDestroy);HANDLE_MSG (hWnd, WM_ACTIVATE, Window_OnActivate);HANDLE_MSG (hWnd, WM_PALETTEISCHANGING, Window_OnPaletteChanging);HANDLE_MSG (hWnd, WM_SYSCOLORCHANGE, Window_SysColorChange);HANDLE_MSG (hWnd, WM_LTANNEVENT, Window_AnnEvent);}return DefWindowProc (hWnd, Message, wParam, lParam);}
Add the code below for Window_AnnEvent immediately before the existing code for Window_OnPaint.
LRESULT Window_AnnEvent(HWND hWnd, WPARAM wParam, LPARAM lParam){UNREFERENCED_PARAMETER(hWnd);switch(wParam){case LTANNEVENT_TOOLCHECKED:L_AnnSetTool(hAutomation, (L_UINT)lParam);break;case LTANNEVENT_AUTOENDSET:// Set tool back to ANNTOOL_SELECT after finished creating annotationL_AnnSetToolBarChecked(hWndToolbar, ANNTOOL_SELECT);break;}return 0;}
Add a forward declaration at the very end of Loadsave.h
LRESULT Window_AnnEvent(HWND hWnd, WPARAM wParam, LPARAM lParam); On the Build menu, select Build LoadSave.exe.
On the Debug menu, select Start Without Debugging.
Save this project to use for testing other annotation code samples and for implementing the Using Automated Annotations in Run Mode tutorial.
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
