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

2.

Select the File->New menu option, click the "projects" tab.

3.

Select "MFC AppWizard".

4.

In the Project Name dialog box, enter Tutorial.

5.

In the Location dialog box, use the examples\classlib\msvc5 directory of your LEAD installation. For example, if you installed LEADTOOLS in c:\ltwin14x, enter c:\ltwin14x\examples\classlib\msvc5\

6.

Click OK.

7.

Choose Single Document and click "Finish", and then OK.

8.

Choose Project->Settings.

9.

In the "Settings For" drop down box, choose "All Configurations".

10.

Click on the C/C++ tab.

11.

In the "Category" drop down box, choose "Preprocessor".

12.

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

13.

Open TutorialDoc.h.

14.

Add the following line immediately before the class CTutorialDoc declaration:

#include "ltwrappr.h"

15.

Click on the "Class View" tab.

16.

Click to open the Tutorial Classes branch.

17.

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

18.

Add the following lines after "//TODO: add construction code here":

LSettings::LoadLibraries(LT_KRN|LT_FIL|LV_KRN|LV_DLG);
LSettings::UnlockSupport(L_SUPPORT_VECTOR, L_KEY_VECTOR);

19.

Select Project->Add To Project->Files... and browse to <your LEAD installation directory>\lib\ltwvc_n.lib .

20.

Click on the "Class View" tab.

21.

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

22.

For Variable Type enter LVectorWindow, and for Variable Declaration put *m_pVectorWindow. Leave Access as "Public" and click OK.

23.

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

24.

In the destructor, add the line:

delete m_pVectorWindow;

 

Your tutorialDoc.cpp should have the following code:

CTutorialDoc::CTutorialDoc()
{
   m_pVectorWindow = new LVectorWindow;
   m_pVectorWindow->SetBackgroundColor(RGB(255,255,255));
}

CTutorialDoc::~CTutorialDoc()
{
   delete m_pVectorWindow;
}

25.

In the ClassView, right click the CTutorialView, choose "Add Windows Message Handler", select WM_CREATE, and click the "Add and Edit" button.

26.

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

27.

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

28.

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.