Implementing Vector Automation

1.

Start Visual C++ 2005

2.

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

3.

From "Project Types" click on Visual C++ to expand it, then select MFC. From the right window select MFC Application.

4.

In the Project Name dialog box, enter "VecAut".

5.

In the Location dialog box, use the examples\ClassLibrary\MSVC directory of your LEAD installation. For example, if you installed LEADTOOLS in c:\ltwin16x, enter c:\ltwin16x\examples\classlibrary\MSVC\ Click OK. Then click "Next"

6.

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

7.

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.

8.

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"

9.

Click on the "Class View" tab.

10.

Click to open the" VecAut Classes" branch.

11.

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

12.

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

 

   LBase::LoadLibraries (LT_KRN|LT_FIL|LV_KRN|LT_TLB|LT_AUT|LT_CON); 
    LSettings::UnlockSupport (L_SUPPORT_VECTOR, (L_TCHAR*)L_KEY_VECTOR); 

13

Create a new file called Imports.cpp in place it beside your project files.

 

a.

n the Project Workspace, click the Solution Explorer tab.

 

b.

Double-click the VecAut folder to open it.

 

c.

Right-click the Source files folder and select Add ŕ New item.

 

d.

Right-click on the Source file

 

e.

Expand Visual C++ tree, if it is not already expanded.

 

f.

Select Code from the sub tree.

 

g.

Select C++ File (.cpp) from the right window.

 

h.

In the name text box, specify Imports.

 

i.

Click the OK button.

 

j.

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) 

14.

Click on the "Class View" tab.

15.

Right click "CVecAutDoc" and select Add ŕ "Add Variable..."

16.

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

17.

Right click "CVecAutDoc" and select Add ŕ "Add Variable..."

18.

For Variable Type enter LContainer, and for Variable Declaration put m_Container. Leave Access as "Public" and click OK.

19.

Right click "CVecAutApp" and select Add ŕ "Add Variable..."

20.

For Variable Type enter LAutomation, and for Variable Declaration put m_Automation. Leave Access as "Public" and click OK.

21.

Right click "CVecAutApp" and select Add ŕ "Add Variable..."

22.

For Variable Type enter LToolbar, and for Variable Declaration put m_Toolbar. Leave Access as "Public" and click OK.

23.

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

24.

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

 

25.

Right click the CMainFrame branch, and choose "Properties".

26.

From the "Properties" window toolbar, click on the Message icon.

Then click on the empty area beside the item "WM_DESTROY" and choose OnDestroy.

27.

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

28.

Right click the CVecAutView class, and choose "Properties".

29.

From the "Properties" window toolbar, click on the Message icon.

Then click on the empty area beside the item "WM_CREATE" and choose OnCreate.

30.

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

31.

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.

32.

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

33.

Click on CVecAutDoc tree view branch, and double click the CVecAutDoc() constructor. Add the line:

m_VectorWindow.SetBackgroundColor (RGB(255,255,255));

34.

Double click the CVecAutDoc branch to open VecAutDoc.h. Add the following include immediately before the class declaration:

#include "c:\program files\lead technologies\leadtools 16\include\classlib\ltwrappr.h"

35.

Open MainFrm.cpp and add the following lines after #include "MainFrm.h":

#include "VecAut.h"
#include "VecAutDoc.h"
extern CVecAutApp theApp;

36.

Open VecAutView.cpp and add the following lines after #include "VecAutView.h":

#include "VecAut.h"
extern CVecAutApp theApp;

37.

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.

38.

Double-click IDR_MAINFRAME.

39.

Click "View" and add a menu item called "Vector Toolbar".

40.

Right click on the newly created item and choose "Add Event handler…"

41.

From the "Class name" drop down box elect "CVecAutApp".

42.

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

43.

Right click on the "Vector Toolbar" item again and choose "Add Event handler…"

44.

From the "Class name" drop down box elect "CVecAutApp".

45.

From the "Messages" list box select "UPDATE_COMMAND_UI" and click "Add and Edit…"

46.

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

47.

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

48.

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.