Implementing Automation - Implementing Vector Automation

Start with the project you created in Initializing and Loading a Vector Image

Take the following steps to create and initialize the automation objects:

  1. Add the following include statements after #include "l_bitmap.h". Note that the path needs to match the path used when the toolkit was installed on your system.
     #include "C:/LEADTOOLS21/Include/ltpnt.h" 
     #include "C:/LEADTOOLS21/Include/lttlb.h" 
     #include "C:/LEADTOOLS21/Include/ltcon.h" 
     #include "C:/LEADTOOLS21/Include/ltaut.h" 
  2. Replace the ResetView function with the following code:
    static L_VOID ResetView(HWND hWnd, pVECTORHANDLE pVector, pAUTOMATIONHANDLE pAutomation) 
    { 
       VECTORPOINT Scale; 
       VECTORPOINT Rotation; 
       VECTORPOINT Translation; 
       POINT       pt; 
       L_AutSetUndoEnabled(pAutomation, FALSE); 
       Scale.x = Scale.y = Scale.z = 1.0; 
       L_VecSetScale(pVector, &Scale, NULL, NULL, 0L); 
       Rotation.x = Rotation.y = Rotation.z = 0.0; 
       L_VecSetRotation(pVector, &Rotation, NULL, NULL, 0L); 
       Translation.x = Translation.y = Translation.z = 0.0; 
       L_VecSetTranslation(pVector, &Translation, NULL, 0L); 
       pt.x = 0; 
       pt.y = 0; 
       L_VecSetPan(pVector, &pt); 
       L_VecSetParallelogram(pVector, NULL, NULL); 
       L_VecSetOrigin(pVector, NULL); 
       L_VecSetCamera(pVector, NULL); 
       L_AutSetUndoEnabled(pAutomation, TRUE); 
       InvalidateRect(hWnd, NULL, FALSE); 
    } 
  3. Add the following new local function before the WndProc function:
    static L_INT EXT_CALLBACK ContainerCallback(pCONTAINERHANDLE pContainer, CONTAINEREVENTTYPE nEventType, L_VOID *pEventData, L_VOID *pUserData) 
    { 
       HWND                 hWnd; 
       pCONTAINEROBJECTDATA pObjectData; 
       switch (nEventType) 
       { 
          case CONTAINER_EVENT_TYPE_DRAW: 
          pObjectData = (pCONTAINEROBJECTDATA)pEventData; 
          if (pObjectData->fState == CONTAINER_STATE_END || pObjectData->fState == CONTAINER_STATE_ABORT) 
          { 
             L_ContainerGetOwner(pContainer, &hWnd); 
             InvalidateRect(hWnd, NULL, FALSE); 
          } 
          break; 
       } 
       return SUCCESS; 
    } 
  4. Add the following local variables to the WndProc function, right after the HDC hDC; statement:
    static pAUTOMATIONHANDLE pAutomation; 
    static pCONTAINERHANDLE pContainer; 
    static pTOOLBARHANDLE pToolbar; 
    CONTAINERMETRICS ContainerMetrics; 
  5. Add the following lines right after the L_VecAttachToWindow function call in the WM_CREATE of WndProc:
    // create the automation handle 
    L_AutInit(&pAutomation); 
    L_AutCreate(pAutomation, AUTOMATION_MODE_VECTOR, 0L); 
    // create the toolbar 
    L_TBInit(&pToolbar); 
    L_TBCreate(pToolbar, hWnd, TEXT("Vector"), TOOLBAR_VECTOR); 
    L_TBSetVisible(pToolbar, TRUE); 
    // add it to the automation object 
    L_AutSetToolbar(pAutomation, pToolbar); 
    // create the container 
    L_ContainerInit(&pContainer); 
    L_ContainerCreate(pContainer, hWnd); 
    // set its callback 
    L_ContainerSetCallback(pContainer, ContainerCallback, NULL); 
    // add it to the automation object 
    L_AutAddContainer(pAutomation, pContainer, &Vector); 
    // set it as the active container 
    L_AutSetActiveContainer(pAutomation, pContainer); 
  6. Change the ResetView function call just before the return 0; statement in WM_CREATE to:
    ResetView( hWnd, &Vector, pAutomation );  
  7. Add the following lines right after the L_VecSetViewport function call in WM_SIZE:
    // set container limits to entire client area   
    ContainerMetrics.nSize = sizeof( CONTAINERMETRICS );   
    ContainerMetrics.dwMask = CMF_LIMITS;   
    CopyRect( &ContainerMetrics.rcLimits, &Rect );   
    L_ContainerSetMetrics ( pContainer, &ContainerMetrics ); 
  8. Add the following lines to the WM_DESTROY message, just before the call to L_VecFree:
    // destroy container 
    L_AutRemoveContainer(pAutomation, pContainer); 
    L_ContainerFree(pContainer); 
    // destroy automation 
    L_AutFree(pAutomation); 
    // destroy toolbar 
    L_TBFree(pToolbar); 
  9. In Imports.cpp add the following #pragma comment lines. Note that the path needs to match the one that is on your system.
    #if defined(FOR_WIN64)  
    #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\x64\\Lvaut_x.lib") 
    #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\x64\\Lvcon_x.lib") 
    #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\x64\\Lvtlb_x.lib") 
    #elif defined(FOR_WIN32)  
    #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\Win32\\Ltaut_u.lib") 
    #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\Win32\\Ltcon_u.lib") 
    #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\Win32\\Lttlb_u.lib") 
    #endif // #if defined(FOR_WIN64)  
  10. Compile and run the demo. You should be able to draw new vector objects and rotate them in 3D, using your mouse and the pan feature.
Help Version 21.0.2021.4.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Container and Automation C API Help