Creating an Empty Vector

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.

1.

Start Visual C++, version 2005.

2.

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 LEAD Technologies\LEADTOOLS 19\Examples\ClassLibrary\MSVC folder, then click OK.

3.

In the first wizard dialog, click "Next".

4.

In the next step, choose Single Document and click "Finish".

5.

From the main menu, choose Project->Properties

6.

In the "Configuration Properties" node, choose "C/C++", then "General".

7.

In the "Additional include directories" dialog box, enter the include\classlib directory of your LEADTOOLS installation. For example, if you installed LEADTOOS in c:\ltwin14x, enter c:\ltwin14x\include\classlib.

8.

Open TutorialDoc.h.

9.

Add the following line immediately before the class CTutorialDoc declaration:

#include "ltwrappr.h" 

10.

Click on the "Class View" tab.

11.

Click to open the Tutorial Classes branch.

12.

Click "CTutorialApp", and then double click the CTutorialApp() constructor.

13.

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);   
  

14.

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".

15.

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 

16.

Click on the "Class View" tab.

17.

Right click "CTutorialDoc" and select "Add Variable..."

18.

For Variable Type enter LVectorWindow*, and for Variable name enter m_pVectorWindow. Leave Access as "Public" and click Finish.

19.

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)); 

20.

In the destructor, add the line:

delete m_pVectorWindow; 

21.

In the ClassView, select the CTutorialView, in the Properties window select Messages shortcut, then select the WM_CREATE.

22.

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; 
} 

22.

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 layeres 
   m_pVectorWindow->Empty (); 
    
   //Create an empty vector layer 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; 
} 

23.

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.

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Vector C++ Class Library Help