Take the following steps to start a project and to add some code that creates a new empty vector handle, and attaches it to a window.
Note: This example is for a 32-bit (NT or Windows 9x) environment.
Start Visual C++, version 2005.
Select the File->New->Project menu option. In the New Project dialog box, make sure to select "Visual C++" "MFC" from the tree on the left of the dialog, and select "MFC Application" as the project template. Give the project the name "Tutorial" and make sure to allocate your project under the following folder C:\LEADTOOLS22\Examples\Vector\ClassLibrary folder, then click OK.
In the first wizard dialog, click "Next".
In the next step, choose Single Document and click "Finish".
From the main menu, choose Project->Properties
In the "Configuration Properties" node, choose "C/C++", then "General".
In the "Additional include directories" dialog box, enter the include\classlib directory of your LEADTOOLS installation. For example, if you installed LEADTOOS in C:\LEADTOOLS22, enter C:\LEADTOOLS22\Include\ClassLib.
Open TutorialDoc.h.
Add the following line immediately before the class CTutorialDoc declaration:
#include "ltwrappr.h"
Click on the "Class View" tab.
Click to open the Tutorial Classes branch.
Click "CTutorialApp", and then double click the CTutorialApp() constructor.
Add the following lines after //TODO: add construction code here
:
LSettings::LoadLibraries (LT_KRN|LT_FIL|LV_KRN|LV_DLG);
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);
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, you may have to change the paths to match your LEADTOOLS installation folder):
#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
Click on the "Class View" tab.
Right click "CTutorialDoc" and select "Add Variable..."
For Variable Type enter LVectorWindow*, and for Variable name enter m_pVectorWindow. Leave Access as "Public" and click Finish.
Click on the CTutorialDoc tree view branch, and double click the CTutorialDoc() constructor. Add the lines:
m_pVectorWindow = new LVectorWindow;
m_pVectorWindow->SetBackgroundColor (RGB(255, 255, 255));
In the destructor, add the line:
delete m_pVectorWindow;
In the ClassView, select the CTutorialView, in the Properties window select Messages shortcut, then select the WM_CREATE.
Code the CTutorialView::OnCreate() function as follows:
int CTutorialView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
L_INT nRet = SUCCESS;
nRet = GetDocument()->m_pVectorWindow->SetWndHandle (m_hWnd);
if(nRet!=SUCCESS)
{
LBase::DisplayErrorFromList ();
return -1;
}
else
{
GetDocument()->m_pVectorWindow->AttachToWindow (m_hWnd);
}
return 0;
}
Modify CTutorialDoc::OnNewDocument() to create a new vector with an empty vector layer. The function should look like this:
BOOL CTutorialDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
//Empty the vector of all objects and layers
m_pVectorWindow->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_pVectorWindow->AddLayer (&MyLayer);
m_pVectorWindow->SetActiveLayer (&MyLayer);
m_pVectorWindow->Reset ();
return TRUE;
}
Compile and run the project by selecting Build->Execute tutorial.exe from the menu. The program should display a white background drawn by the vector handle.