To create a new empty vector handle and attach it to a window:
Start Visual C++, version 2005.
Select the File->New->Project menu option.
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 C:\LEADTOOLS23\Examples\Vector\CDLL folder click OK.
When the Win32 Application Wizard initializes, click Finish.
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 handleRECT 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 vectorL_VecPaint( hdc, &Vector, TRUE );EndPaint(hWnd, &ps);break;case WM_DESTROY:// free the vector handleL_VecFree( &Vector );PostQuitMessage(0);break;case WM_CREATE:// initiates the vector handleL_VecInit ( &Vector );// set wireframe modeL_VecSetPolygonMode ( &Vector, VECTOR_POLYGON_LINE );// attach it to the main windowL_VecAttachToWindow ( hWnd, &Vector, VECTOR_ENGINE_DOUBLEBUFFER );// set default viewResetView( hWnd, &Vector );break;case WM_SIZE:// set the vector viewport to all client areaGetClientRect( hWnd, &Rect );L_VecSetViewport( &Vector, &Rect );break;default:return DefWindowProc(hWnd, message, wParam, lParam);}return 0;}
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;}
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:\LEADTOOLS23\Include\L_Bitmap.h"#include "C:\LEADTOOLS23\Include\Ltvkrn.h"
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.
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\\Ltvkrn_x.lib')#pragma comment( lib, '..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltkrn_x.lib')#else#pragma comment( lib, '..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltvkrn_u.lib')#pragma comment( lib, '..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltkrn_u.lib')#endif
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 windowInvalidateRect( hWnd, NULL, FALSE );}
Compile and run the project by selecting Build, Rebuild Solution, and Debug Start Without Debugging from the menu.
The program should display a white background drawn by the vector handle.