Start Visual C++ 2005
Select the File->New menu option, click the "projects" tab.
From "Project Types" click on Visual C++ to expand it, then select MFC. From the right window select MFC Application.
In the Project Name dialog box, enter "VecAut".
In the Location dialog box, use the \Examples\Paint directory of your LEAD installation. For example, if you installed LEADTOOLS in C:\LEADTOOLS22, enter C:\LEADTOOLS22\Examples\Paint Click OK. Then click "Next"
Choose Single Document and click "Finish", and then OK.
Click on the "Solution Explorer" tab, and then click on the VecAut project to expand it. Click on the Header files, then Open VecAut.h.
Add the following line immediately before the class CVecAutApp declaration, (keep in mind, you may have to change the path to where the header files reside):
#include "..\..\..\..\..\include\ClassLib\ltwrappr.h"
Click on the "Class View" tab.
Click to open the "VecAut Classes" branch.
Click "CVecAutApp", and then double click the CVecAutApp() constructor.
Add the following lines after //TODO: add construction code here:
LBase::LoadLibraries(LT_KRN|LT_FIL|LV_KRN|LT_TLB|LT_AUT|LT_CON);
L_TCHAR * pszLicenseFile = L"Replace this with the path to the LEADTOOLS license file";
L_TCHAR * pszDeveloperKey = L"Replace this with your developer key";
LSettings::SetLicenseFile(pszLicenseFile, pszDeveloperKey);
Create a new file called Imports.cpp in place it beside your project files.
In the Project Workspace, click the Solution Explorer tab.
Double-click the VecAut folder to open it.
Right-click the Source files folder and select Add New item.
Right-click on the Source file.
Expand Visual C++ tree, if it is not already expanded.
Select Code from the sub tree.
Select C++ File (.cpp) from the right window.
In the name text box, specify Imports.
Click the OK button.
Double-click the imports.cpp in the solution Explorer and add the following lines:
#include "StdAfx.h"
#if defined(WIN64)
#pragma comment(lib, "..\\..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltwvc_x.lib")
#else
#pragma comment(lib, "..\\..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltwvc_u.lib")
#endif // #if defined(WIN64)
Click on the "Class View" tab.
Right click "CVecAutDoc" and select Add "Add Variable..."
For Variable Type enter LVectorWindow, and for Variable Declaration put m_VectorWindow. Leave Access as "Public" and click OK.
Right click "CVecAutDoc" and select Add "Add Variable..."
For Variable Type enter LContainer, and for Variable Declaration put m_Container. Leave Access as "Public" and click OK.
Right click "CVecAutApp" and select Add "Add Variable..."
For Variable Type enter LAutomation, and for Variable Declaration put m_Automation. Leave Access as "Public" and click OK.
Right click "CVecAutApp" and select Add "Add Variable..."
For Variable Type enter LToolbar, and for Variable Declaration put m_Toolbar. Leave Access as "Public" and click OK.
Click to open the CMainFrame branch. Double click the CMainFrame() constructor and add code so that the constructor looks like the following:
CMainFrame::CMainFrame()
{
theApp.m_Automation.Initialize();
theApp.m_Automation.Create(AUTOMATION_MODE_VECTOR);
theApp.m_Toolbar.Initialize();
}
Double click the CMainFrame::OnCreate() member function, and add the following code immediately after the first opening bracket {:
theApp.m_Toolbar.Create(m_hWnd, (L_TCHAR*)TEXT("Vector"), TOOLBAR_VECTOR);
theApp.m_Toolbar.SetRows(8);
POINT pt;
RECT rcClient;
GetClientRect(&rcClient);
ClientToScreen(&rcClient);
pt.x = rcClient.left;
pt.y = rcClient.top;
theApp.m_Toolbar.SetPosition(&pt, TOOLBAR_POSITION_TOP | TOOLBAR_POSITION_LEFT);
theApp.m_Automation.SetToolbar(&theApp.m_Toolbar);
Right click the CMainFrame branch, and choose "Properties".
From the "Properties" window toolbar, click on the Message icon. Then click on the empty area beside the item "WM_DESTROY" and choose OnDestroy.
Add the following code after the opening bracket {:
CVecAutDoc* pDoc = (CVecAutDoc*)GetActiveDocument();
theApp.m_Automation.RemoveContainer(&pDoc->m_Container);
pDoc->m_Container.Free();
if (theApp.m_Automation.IsValid())
{
theApp.m_Toolbar.Free();
theApp.m_Automation.Free();
}
Right click the CVecAutView class, and choose "Properties".
From the "Properties" window toolbar, click on the Message icon. Then click on the empty area beside the item "WM_CREATE" and choose OnCreate.
Add the following code to replace the //TODO: ...
GetDocument()-> m_VectorWindow.SetBackgroundColor (m_hWnd);
GetDocument()->m_VectorWindow. AttachToWindow(m_hWnd);
GetDocument()->m_Container.Initialize();
GetDocument()->m_Container.Create(m_hWnd);
theApp.m_Automation.AddContainer(&GetDocument()->m_Container, GetDocument()->m_VectorWindow.GetHandle());
theApp.m_Automation.SetActiveContainer(&GetDocument()->m_Container);
Right click the CVecAutView class, and choose "Properties". From the "Properties" window toolbar, click on the Message icon. Then click on the empty area beside the item "WM_SIZE" and choose OnSize.
Add the following code to replace the // TODO:...
CONTAINERMETRICS ContainerMetrics;
RECT Rect;
SetRect(&Rect, 0, 0, cx, cy);
ContainerMetrics.nSize = sizeof(CONTAINERMETRICS);
ContainerMetrics.dwMask = CMF_LIMITS;
CopyRect(&ContainerMetrics.rcLimits, &Rect);
GetDocument()->m_Container.SetMetrics(&ContainerMetrics);
Click on CVecAutDoc tree view branch, and double click the CVecAutDoc() constructor. Add the line:
m_VectorWindow. SetBackgroundColor (RGB(255,255,255));
Double click the CVecAutDoc branch to open VecAutDoc.h. Add the following include immediately before the class declaration:
#include "C:\LEADTOOLS22\Include\classlib\ltwrappr.h"
Open MainFrm.cpp and add the following lines after #include "MainFrm.h":
#include "VecAut.h"
#include "VecAutDoc.h"
extern CVecAutApp theApp;
Open VecAutView.cpp and add the following lines after #include "VecAutView.h":
#include "VecAut.h"
extern CVecAutApp theApp;
Click on the "Resource View" tab of the project workspace and click to open the "VecAut resources" branch, and then click to open the "Menu" branch.
Double-click IDR_MAINFRAME.
Click "View" and add a menu item called "Vector Toolbar".
Right click on the newly created item and choose "Add Event handler".
From the "Class name" drop down box elect "CVecAutApp".
From the "Messages" list box select "COMMAND" and click "Add and Edit..." Code the function as follows:
void CVecAutApp::OnViewVectortoolbar()
{
L_BOOL bVisible;
bVisible = m_Toolbar.IsVisible();
m_Toolbar.m_Toolbar.SetVisible(!bVisible);
}
Right click on the "Vector Toolbar" item again and choose "Add Event handler"
From the "Class name" drop down box elect "CVecAutApp".
From the "Messages" list box select "UPDATE_COMMAND_UI" and click "Add and Edit"
Click "Edit Code", and Add code to the two newly created member functions as follows:
void CVecAutApp::OnUpdateViewVectortoolbar(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_Toolbar.IsVisible());
}
Modify CVecAutDoc::OnNewDocument() to create a new vector with an empty vector layer. The function should look like this.
BOOL CVecAutDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
//Empty the vector of all objects and layers
m_VectorWindow.Empty();
//Create an empty vector layer
VECTORLAYERDESC VectorLayerDesc;
VectorLayerDesc.nSize = sizeof(VECTORLAYERDESC);
lstrcpy(VectorLayerDesc.szName, TEXT("First Layer"));
VectorLayerDesc.bVisible= TRUE;
VectorLayerDesc.bLocked = FALSE;
VectorLayerDesc.dwTag = 0;
LVectorLayer MyLayer(&VectorLayerDesc);
m_VectorWindow.AddLayer(&MyLayer);
m_VectorWindow.SetActiveLayer(&MyLayer);
m_VectorWindow.EnableAutoScroll(TRUE);
VECTORPOINT min, max;
min.x = min.y = min.z = max.z = 0.0;
max.x = max.y = 100.0;
m_VectorWindow.SetParallelogram(&min,&max);
m_VectorWindow.Reset();
return TRUE;
}
Compile and run the project by selecting Build->Execute VecAut.exe from the menu. Choose "View->Vector Toolbar" from the menu and begin drawing with the vector tools.