Implementing a Non-automated Annotations Program

Take the following steps to create and run a program that implements non-automated annotations.

  1. Create a new directory in the LEADTOOLS 20\Examples\CDLL directory called AnnNonAuto.

  2. Copy everything in the Color directory into the AnnNonAuto directory.

  3. Compile the project as is and run Color.exe to familiarize yourself with the 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. Open the imports.cpp file and add the items 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\\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\\Ltann_u.lib")   
       #endif // #if defined(WIN64) 

  5. Declare the following global variables in Color.cpp:

    HANNOBJECT hContainer;   
    HANNOBJECT MyNote; 

    and the following functions:

    void TestCreateAnn(HWND hWnd);   
    void TestCreateNoteAnn(HWND hWnd); 

  6. Add the following code:

    void TestCreateAnn(HWND hWnd) 
    { 
       RECT rClientArea; /* Client area of the current window */ 
       HDC hWindowDC;  /* Device context of the current window */ 
       ANNRECT ContainerRect; /* Defining rectangle for the container */ 
       RECT rAnnBounds; /* Bounding rectangle for displaying */ 
       /* Get the device context of the current window */ 
       hWindowDC = GetDC (hWnd); 
       /* Get the client area of the current window */ 
       GetClientRect(hWnd, &rClientArea); 
       /* Create the annotation container, which we will use as the root container */ 
       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 annotation scalars and offsets, assuming that the display 
       dimensions are the same as the client area dimensions */ 
       L_AnnSetScalarX(hContainer, (L_DOUBLE) rClientArea.right / BITMAPWIDTH(&Data.BitmapHandle), 0); 
       L_AnnSetScalarY(hContainer, (L_DOUBLE) rClientArea.bottom / BITMAPHEIGHT(&Data.BitmapHandle), 0); 
       L_AnnSetOffsetX(hContainer, (L_DOUBLE) 0, 0); 
       L_AnnSetOffsetY(hContainer, (L_DOUBLE) 0, 0); 
       L_AnnGetBoundingRect(hContainer, &rAnnBounds, NULL); 
       L_AnnDraw(hWindowDC, &rAnnBounds, hContainer); 
       ReleaseDC(hWnd, hWindowDC); 
       return; 
    } 

  7. Add the following code:

    void TestCreateNoteAnn(HWND hWnd) 
    { 
       ANNRECT ContainerRect; 
       ANNRECT MyNoteRect; 
       RECT rAnnBounds; 
       HDC hWindowDC; 
       hWindowDC = GetDC(hWnd); 
       /* Create a Note Annotation */ 
       L_AnnCreateItem(hContainer, ANNOBJECT_NOTE, TRUE, &MyNote); 
       L_AnnGetRect(hContainer, &ContainerRect, NULL); 
       /* Size and position the note */ 
       MyNoteRect.left = ContainerRect.right / 8; 
       MyNoteRect.top = ContainerRect.bottom / 8; 
       MyNoteRect.right = ContainerRect.right / 2; 
       MyNoteRect.bottom = ContainerRect.bottom / 2; 
       L_AnnSetRect(MyNote, &MyNoteRect); 
       /* Set the text of the note  */ 
       L_AnnSetText(MyNote, TEXT("This is my text"), 0); 
       L_AnnSetBackColor(MyNote, RGB(0, 255, 255), 0); 
       L_AnnSetFontBold(MyNote, TRUE, 0); 
       L_AnnSetFontItalic(MyNote, FALSE, 0); 
       L_AnnSetFontName(MyNote, TEXT("Arial"), 0); 
       L_AnnSetFontSize(MyNote,16, 0); 
       L_AnnSetFontStrikeThrough(MyNote, FALSE, 0); 
       L_AnnSetFontUnderline(MyNote, TRUE, 0); 
       L_AnnSetForeColor(MyNote, RGB(255, 0, 0), 0); 
       /* Display the note */ 
       L_AnnGetBoundingRect(MyNote, &rAnnBounds, NULL); 
       L_AnnDraw(hWindowDC, &rAnnBounds, MyNote); 
       /* Remove the queued paint message */ 
       ValidateRect(hWnd, &rAnnBounds); 
       ReleaseDC(hWnd, hWindowDC); 
       return; 
    } 

  8. Add the following lines of code to Window_OnCreate, just before return (TRUE);:

    TestCreateAnn(hWnd);   
    TestCreateNoteAnn(hWnd); 

  9. Add the following line to Window_OnPaint:

    L_AnnDraw(hdc, &ps.rcPaint, hContainer); 
    immediately after
    if(hpalPaint)   
       SelectPalette(hdc, hPalette, FALSE); 

  10. Add the following line to Window_OnDestroy, immediately before PostQuitMessage:

    L_AnnDestroy(hContainer, ANNFLAG_RECURSE); 

  11. On the Build menu, select Build Color.exe.

  12. On the Debug menu, select Start Without Debugging. Keep this project for testing other annotation code samples and for implementing Using Non-automated Annotations in Run Mode

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help