Creating an Empty Vector Handle and Attaching it to a Window

To create a new empty vector handle and attach it to a window:

1. Start Visual C++, version 2005.
2. Select the File->New->Project menu option.
3. In the New Project dialog box, make sure to select Visual C++ Win32 from the tree on the left of the dialog, and select Win32 Project as the project template.

Give the project the name "Tutorial " and make sure to allocate your project under the following folder LEAD Technologies\LEADTOOLS EVAL 19\Examples\CDLL folder click OK.

4. When the Win32 Application Wizard initializes, click Finish.
   
5. Change the WndProc function to look like this:

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, (DLGPROC)About); 
         break; 
         case IDM_EXIT: 
         DestroyWindow(hWnd); 
         break; 
default: 
         return DefWindowProc(hWnd, message, wParam, lParam); 
      } 
      break; 
      case WM_PAINT: 
      hdc = BeginPaint(hWnd, &ps); 
      // draw the vector 
      L_VecPaint( hdc, &Vector, TRUE ); 
      EndPaint(hWnd, &ps); 
      break; 
      case WM_DESTROY: 
      // free the vector handle 
      L_VecFree( &Vector ); 
      PostQuitMessage(0); 
      break; 
      case WM_CREATE: 
      // initiates the vector handle 
      L_VecInit ( &Vector ); 
      // 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 ); 
      break; 
      case WM_SIZE: 
      // set the vector viewport to all client area 
      GetClientRect( hWnd, &Rect ); 
      L_VecSetViewport( &Vector, &Rect ); 
      break; 
default: 
      return DefWindowProc(hWnd, message, wParam, lParam); 
   } 
   return 0; 
} 

6.

Change the _tWinMain function to look like this:

int APIENTRY _tWinMain(HINSTANCE hInstance, 
HINSTANCE hPrevInstance, 
LPTSTR    lpCmdLine, 
int       nCmdShow) 
{ 
   const L_TCHAR szClassName[] = TEXT("lead_vector_tutorial"); 
   WNDCLASSEX WndClass; 
   HWND hWnd; 
   MSG Msg; 
    
   UNREFERENCED_PARAMETER( hPrevInstance ); 
   UNREFERENCED_PARAMETER( lpCmdLine ); 
    
   WndClass.cbSize = sizeof( WNDCLASSEX ); 
   WndClass.style = CS_HREDRAW | CS_VREDRAW; 
   WndClass.lpfnWndProc = WndProc; 
   WndClass.cbClsExtra = 0; 
   WndClass.cbWndExtra = 0; 
   WndClass.hInstance = hInst; 
   WndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION ); 
   WndClass.hCursor = LoadCursor( NULL, IDC_ARROW ); 
   WndClass.hbrBackground = NULL; 
   WndClass.lpszMenuName = NULL; 
   WndClass.lpszClassName = szClassName; 
   WndClass.hIconSm = NULL; 
    
   RegisterClassEx( &WndClass ); 
    
   hWnd = CreateWindowEx( 0L, szClassName, 
   TEXT("VectorTutorial"), 
   WS_OVERLAPPEDWINDOW, 
   CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 
   NULL, NULL, hInst, NULL ); 
    
   ShowWindow( hWnd, nCmdShow ); 
   UpdateWindow( hWnd ); 
    
   while( GetMessage( &Msg, NULL, 0, 0 ) != 0 ) 
   { 
      TranslateMessage( &Msg ); 
      DispatchMessage( &Msg ); 
   } 
    
   UnregisterClass( szClassName, hInst ); 
    
   return (int)Msg.wParam; 
} 

7.

Add the following includes to the top of your CPP file (Note that the include statements will have to be modified to match the location of the LEADTOOLS toolkit on your system):

#ifndef LTVXX_CONFIG   
#define LTVXX_CONFIG   
#endif   
#include "C:\LEADTOOLS 19\Include\L_Bitmap.h"   
#include "C:\LEADTOOLS 19\Include\Lvkrn.h" 

8.

In the Solution Explorer, right-click your project tutorial and select Add New Item, and add a new CPP file and name it Imports.cpp.

9.

Add the following code to Imports.cpp you just created (Note that the pragma statements will have to be modified to match the location of the LEADTOOLS toolkit on your system):

#include 'stdafx.h' 
#if defined(WIN64) 
#pragma comment( lib, '..\\..\\..\\..\\Lib\\CDLL\\x64\\Lvkrn_x.lib') 
#pragma comment( lib, '..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltkrn_x.lib') 
#else 
#pragma comment( lib, '..\\..\\..\\..\\Lib\\CDLL\\Win32\\Lvkrn_u.lib') 
#pragma comment( lib, '..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltkrn_u.lib') 
#endif 

 

10.

Add the following code to Tutorial.cpp above the WndProc function:

static L_VOID ResetView( HWND hWnd, pVECTORHANDLE pVector ) 
{ 
   // let the vector toolkit calculates the extent of the current drawing. 
   L_VecSetParallelogram ( pVector, NULL, NULL ); 
  
   // let the vector toolkits calculates the origin of current drawing. 
   L_VecSetOrigin ( pVector, NULL ); 
  
   // let the vector toolkits calculates the default camera position (top-view) 
   L_VecSetCamera ( pVector, NULL ); 
  
   // cause a redraw of our main window 
   InvalidateRect( hWnd, NULL, FALSE ); 
} 

11.

Compile and run the project by selecting Build Rebuild Solution and Debug Start Without Debugging from the menu.

12.

The program should display a white background drawn by the vector handle.

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Vector C API Help