Available in LEADTOOLS Imaging Pro, Vector, Document, and Medical Imaging toolkits. |
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 Win32->Win32 Project as the project type. Give the project the name "vector" and press Enter, and then click on Finish. |
|
4. |
Change the path of the output exe file path to the Leadtools Bin directory, |
|
|
a. |
Right click on the project in the Solution Explorer window, and choose Properties. |
|
b. |
From the left-side window, choose Configuration Properties -> Linker. |
|
c. |
In the right-side window, change the value of the Output File to: (Please note to change the path to the location of the LEADTOOLS toolkit on your machine, and if you are working on 64 platform, change the Win32 to x64 in the path.) C:\Program Files\LEAD Technologies\LEADTOOLS 16\Bin\CDLL\Win32\$(ProjectName).exe |
|
d. |
And then press Ok. |
5. |
Now go back to solution explorer window, and open stdafx.h file. |
6. |
Add the following lines at the end of the file: (Please note to change the path to the location of the LEADTOOLS toolkit on your machine) |
// LEAD Header Files
#include "C:/Program Files/LEAD Technologies/LEADTOOLS 16/Include/L_Bitmap.h"
#include "C:/Program Files/LEAD Technologies/LEADTOOLS 16/Include/Lvkrn.h"
7. |
Create a new file called Imports.cpp, |
|
|
a. |
In Solution Explorer, right click on Source Files, select Add, and then select New Item. |
|
b. |
In the Add New Item dialog, in the Categories window, choose Visual C++ -> Code, then in the Templates window, choose C++ File (cpp). |
|
c. |
In the Name field, enter the name of the file as Imports.cpp, then press Enter. |
|
d. |
Now open the Imports.cpp file (if it isnt already open) by double clicking on it in the Solution Explorer window, and copy and paste the following code into it: |
#include "StdAfx.h"
#if defined(FOR_WIN64)
#pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\x64\\Ltkrn_x.lib")
#pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\x64\\Ltfil_x.lib")
#pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\x64\\Lvkrn_x.lib")
#elif defined(FOR_WIN32)
#pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\Win32\\Ltkrn_u.lib")
#pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\Win32\\Ltfil_u.lib")
#pragma comment(lib, "C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Lib\\CDLL\\Win32\\Lvkrn_u.lib")
#endif // #if defined(FOR_WIN64)
8. |
Change the WndProc function to look like this: (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:
// initiates the vector handle and load it
L_VecInit
( &Vector );
//note that LEAD represents the location of the LEADTOOLS
//toolkit on your system
// Note: change the path to the LEADTOOLS toolkit
// location on your system.
L_VecLoadFile
( TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 16\\Images\\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;
}
9. |
Change the _tWinMain function to look like this: |
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;
// unlock vector support
L_UnlockSupport
( L_SUPPORT_VECTOR, L_KEY_VECTOR );
// 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;
}
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. |