Take the following steps to create a project and add code that will create a new container handle:
Start Visual C++, version 2005.
Select the File >New >Project menu option.
In the New Project dialog box, enter the location (C:\LEADTOOLS23\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.
Change the path of the output exe file path to the LEADTOOLS Bin directory, as follows:
C:\\LEADTOOLS23\\Bin\\CDLL\\Win32\\$(ProjectName).exe
Now go back to the Solution Explorer window, and open the stdafx.h file.
Append the following lines to the end of the file:
// LEAD Header Files
#include "C:/LEADTOOLS23/Include/L_Bitmap.h"
#include "C:/LEADTOOLS23/Include/Ltvkrn.h"
Visual C++ -> Code
. Then in the Templates window, choose C++ File (cpp)
.#include "StdAfx.h"
#if defined(FOR_WIN64)
#pragma comment(lib, "C:\\LEADTOOLS23\\Lib\\CDLL\\x64\\Ltkrn_x.lib")
#pragma comment(lib, "C:\\LEADTOOLS23\\Lib\\CDLL\\x64\\Ltfil_x.lib")
#pragma comment(lib, "C:\\LEADTOOLS23\\Lib\\CDLL\\x64\\Ltvkrn_x.lib")
#elif defined(FOR_WIN32)
#pragma comment(lib, "C:\\LEADTOOLS23\\Lib\\CDLL\\Win32\\Ltkrn_u.lib")
#pragma comment(lib, "C:\\LEADTOOLS23\\Lib\\CDLL\\Win32\\Ltfil_u.lib")
#pragma comment(lib, "C:\\LEADTOOLS23\\Lib\\CDLL\\Win32\\Ltvkrn_u.lib")
#endif // #if defined(FOR_WIN64)
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);
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:
// 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 );
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;
}
_tWinMain
function to look like the following code:
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = 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,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
wcscpy_s( szTitle, TEXT("Vector Automation Tutorial"));
wcscpy_s( szWindowClass, TEXT("lead_vector_tutorial"));
MyRegisterClass(hInstance);
// 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))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
Compile and run the project by selecting Build->Rebuild Solution from the menu, and then Debug->Start Without Debugging.
The program should display a vector image by the vector handle.