Implementing Automation - Initializing and Loading a Vector Image

Take the following steps to create a project and add code that will create a new container handle:

  1. Start Visual C++, version 2005.

  2. Select the File >New >Project menu option.

  3. In the New Project dialog box, enter the location (c:\lead\examples\vector). Make sure to select the Win32->Win32 Project as the project type. Give the project the name "vector" and press Enter, and then click Finish.

  4. Change the path of the output exe file path to the LEADTOOLS Bin directory, as follows:

    1. Right-click the project in the Solution Explorer window, and choose Properties.
    2. From the left-side window, choose Configuration Properties -> Linker.
    3. In the right-side window, change the value of the Output File to the location of the LEADTOOLS toolkit on your machine, and if you are working on an x64 platform, change the Win32 in the path to x64. The default location is
    4. Press OK.
  5. Now go back to the Solution Explorer window, and open the stdafx.h file.

  6. Append the following lines to the end of the file:

    // LEAD Header Files 
    #include "C:/LEADTOOLS21/Include/L_Bitmap.h" 
    #include "C:/LEADTOOLS21/Include/Ltvkrn.h" 

  7. Create a new file called Imports.cpp, as follows:
    1. In the Solution Explorer, right-click Source Files, select Add, and then select New Item.
    2. In the Add New Item dialog, in the Categories window, choose Visual C++ -> Code. Then in the Templates window, choose C++ File (cpp).
    3. In the Name field, enter the name of the file as Imports.cpp, and then press Enter.
    4. Now open the Imports.cpp file (if it is not already open) by double-clicking it in the Solution Explorer window. Copy and paste the following code into it:
      #include "StdAfx.h" 
      #if defined(FOR_WIN64)  
         #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\x64\\Ltkrn_x.lib") 
         #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\x64\\Ltfil_x.lib") 
         #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\x64\\Ltvkrn_x.lib") 
      #elif defined(FOR_WIN32)  
         #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\Win32\\Ltkrn_u.lib") 
         #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\Win32\\Ltfil_u.lib") 
         #pragma comment(lib, "C:\\LEADTOOLS21\\Lib\\CDLLVC10\\Win32\\Ltvkrn_u.lib") 
      #endif // #if defined(FOR_WIN64) 
  8. Change the ‘WndProc’ function to look like the following code: (Note: search for random.dxf, and change the path to the LEADTOOLS toolkit location on your system).
    /* This code will do the basic job of loading and painting the bitmap. */ 
    static L_VOID ResetView( HWND hWnd, pVECTORHANDLE pVector ) 
       VECTORPOINT Scale; 
       VECTORPOINT Rotation; 
       VECTORPOINT Translation; 
       POINT       pt; 
       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 ); 
       InvalidateRect( hWnd, NULL, FALSE ); 
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 
       int wmId, wmEvent; 
       PAINTSTRUCT ps; 
       HDC hdc; 
       static VECTORHANDLE Vector;  // our vector handle 
       RECT Rect; 
       switch (message) 
          case WM_COMMAND: 
          wmId    = LOWORD(wParam); 
          wmEvent = HIWORD(wParam); 
          // Parse the menu selections: 
          switch (wmId) 
             case IDM_ABOUT: 
             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); 
             case IDM_EXIT: 
             return DefWindowProc(hWnd, message, wParam, lParam); 
          case WM_PAINT: 
          hdc = BeginPaint(hWnd, &ps); 
          // draw the vector 
          L_VecPaint  ( hdc, &Vector, TRUE ); 
          EndPaint(hWnd, &ps); 
          case WM_DESTROY: 
          // free the vector handle 
          L_VecFree  ( &Vector ); 
          case WM_CREATE: 
          // initiate the vector handle and load it 
          L_VecInit  ( &Vector ); 
          // note that LEAD represents the location of the LEADTOOLS 
          //t oolkit on your system 
          // Note: change the path to the LEADTOOLS toolkit 
          // location on your system. 
          L_VecLoadFile  ( MAKE_IMAGE_PATH(TEXT("random.dxf")), &Vector, NULL, NULL ); 
          // set wireframe mode 
          L_VecSetPolygonMode  ( &Vector, VECTOR_POLYGON_LINE ); 
          // attach it to the main window 
          L_VecAttachToWindow  ( hWnd, &Vector, VECTOR_ENGINE_DOUBLEBUFFER ); 
          // set default view 
          ResetView( hWnd, &Vector ); 
          case WM_SIZE: 
          // set the vector viewport to all client area 
          GetClientRect( hWnd, &Rect ); 
          L_VecSetViewport  ( &Vector, &Rect ); 
          return DefWindowProc(hWnd, message, wParam, lParam); 
       return 0; 
  9. Change the _tWinMain function to look like the following code:
    ATOM MyRegisterClass(HINSTANCE hInstance) 
       WNDCLASSEX wcex; 
       wcex.cbSize = sizeof(WNDCLASSEX);         = CS_HREDRAW | CS_VREDRAW ; 
       wcex.lpfnWndProc   = WndProc; 
       wcex.cbClsExtra      = 0; 
       wcex.cbWndExtra      = 0; 
       wcex.hInstance      = hInstance; 
       wcex.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VECTOR)); 
       wcex.hCursor      = LoadCursor(NULL, IDC_ARROW); 
       wcex.hbrBackground   = (HBRUSH)(COLOR_WINDOW+1); 
       wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_VECTOR); 
       wcex.lpszClassName   = szWindowClass; 
       wcex.hIconSm      = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));; 
       return RegisterClassEx(&wcex); 
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 
       HWND hWnd; 
       hInst = hInstance; // Store instance handle in our global variable 
       hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 
       if (!hWnd) 
          return FALSE; 
       ShowWindow(hWnd, nCmdShow); 
       return TRUE; 
    int APIENTRY _tWinMain(HINSTANCE hInstance, 
    HINSTANCE hPrevInstance, 
    LPTSTR    lpCmdLine, 
    int       nCmdShow) 
       MSG msg; 
       HACCEL hAccelTable; 
       // Initialize global strings 
       wcscpy_s( szTitle, TEXT("Vector Automation Tutorial")); 
       wcscpy_s( szWindowClass, TEXT("lead_vector_tutorial")); 
       // Perform application initialization: 
       if (!InitInstance (hInstance, nCmdShow)) 
          return FALSE; 
       hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_VECTOR)); 
       // Main message loop: 
       while (GetMessage(&msg, NULL, 0, 0)) 
          if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
       return (int) msg.wParam; 
  10. Compile and run the project by selecting Build->Rebuild Solution from the menu, and then Debug->Start Without Debugging.

  11. The program should display a vector image by the vector handle.

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