The Automation Container

Start with the project you created in Tutorial 2: Vector Load and Save.

Take the following steps to add the ability to edit objects using automation.

1.

In the project workspace, click on the Class View tab and then click to open the "VecAut classes" branch.

2.

Right click the "CVecAutApp" class and select Add à "Add Variable..."

3.

For "Variable Type" enter L_BOOL.

4.

For "Variable Declaration" enter m_bToolbarDrawing. This variable is will be set to TRUE when drawing with the automation, and set to FALSE when the pointer (NONE) is selected.

5.

Click to open the "CVecAutApp" class branch.

6.

Double-click the "CVecAutApp" constructor.

7.

Add the following line after the last call to LSettings::UnlockSupport ():

m_bToolbarDrawing = FALSE;

8.

It is necessary to derive a class from LContainer and override the "ContainerCallBack" function. This is used to set the m_bToolBarDrawing variable.

9.

Right click the "VecAut classes" branch and choose Add à "Class..."

10.

From "Categories" choose "C++ Class".

11.

For "Class Name" enter "MyContainer".

12.

For "Base Class" enter "LContainer".

13.

Click "Finish".

14.

Click "Class view" tab. Double click on "MyContainer" to go to the class definition. Then add the following lines:

public:
   L_INT ContainerCallBack(CONTAINEREVENTTYPE nEventType, L_VOID  * pEventData);

15.

Replace the auto generated #Include line with the following #Include, (keep in mind, you may have to change the path to where the header files reside):

#include "..\..\..\..\..\include\ClassLib\ltwrappr.h"

 

16.

In "MyContainer.cpp" add the following code:

 

L_INT MyContainer::ContainerCallBack(CONTAINEREVENTTYPE nEventType, L_VOID  * pEventData)
{
   if (nEventType == CONTAINER_EVENT_TYPE_DRAW)
   {
      pCONTAINEROBJECTDATA pContainerObjectData;

      pContainerObjectData = (pCONTAINEROBJECTDATA)pEventData;
      switch (pContainerObjectData->fState)
      {
      case CONTAINER_STATE_BEGIN: //start
         theApp.m_bToolbarDrawing = TRUE;
         break;

      case CONTAINER_STATE_PROCESS: //drawing
         //Do nothing
         break;

      case CONTAINER_STATE_END://finished
         theApp.m_bToolbarDrawing = FALSE;
         break;
      }
   }
   return LContainer::ContainerCallBack (nEventType, pEventData);
}

17.

Go to the top of MyContainer.cpp, and add the following lines after the last #include:

#include "VecAut.h"
extern CVecAutApp theApp;

18.

Now it is necessary to derive a class from LVectorWindow and override the MsgProcCallBack() member function to process mouse messages.

19.

Right click the "VecAut classes" branch and choose Add à "Class..."

20.

From "Categories" choose "C++ Class".

21.

For "Class Name" enter "MyVectorWindow ".

22.

For "Base Class" enter "LVectorWindow".

23.

Click "Finish".

24.

You will get a dialog box stating that "The New Class Wizard could not find the appropriate header file(s)..." Click "OK".

25.

Click "Class view" tab. Double click on "MyVectorWindow" to go to the class definition. Then add the following lines:

26.

public:

LRESULT MsgProcCallBack(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 

27.

Replace the auto generated #Include line with the following #Include, (keep in mind, you may have to change the path to where the header files reside):

 

1)

28.

Double click the "MsgProcCallBack" branch and add the following code:

LRESULT MyVectorWindow::MsgProcCallBack(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   switch (uMsg)
   {
   case WM_RBUTTONDOWN:
      {
         if (theApp.m_bToolbarDrawing == FALSE)
         {
         LVectorObject MyObject;
         POINT point;

         point.x = LOWORD(lParam); 
         point.y = HIWORD(lParam); 
         HitTest(&point, &MyObject);
         theApp.m_Automation.EditVectorObject (&MyObject);
         }
      }
   }
   return  LVectorWindow::MsgProcCallBack( hWnd, uMsg, wParam, lParam);
}

29.

Click on the "Class View" tab. Then click to open the "VecAut classes" branch.

30.

Click to open the "CVecAutDoc" branch.

31.

Double-click the m_VectorWindow member variable.

32.

Change the declaration from :

LVectorWIndow m_VectorWindow
to: 
MyVectorWindow m_VectorWindow;

33.

Go to the top of MyVectorWindow.cpp, and add the following lines after the last #include:

#include "VecAut.h"
extern CVecAutApp theApp;

34.

Open VecAutDoc.h and after #include "ltwrappr.h" add the following line:

#include "MyVectorWindow.h"

35.

Now add code to set the container properties. These affect the look of a selected vector object.

36.

Click to open the "CVecAutView" branch in the "Class View" tab.

37.

Double click the "OnCreate" member function, and add the following local variable:

CONTAINERMETRICS ContainerMetrics;

38.

Add the following code before the "return 0"

    //Set the container metrics
    ContainerMetrics.dwMask = 
      CMF_BORDERCOLOR | 
      CMF_HANDLECOLOR | 
      CMF_HANDLEHEIGHT | 
      CMF_HANDLEWIDTH | 
      CMF_ENABLEHANDLES;
   ContainerMetrics.crBorder = RGB(255,0,0);
   ContainerMetrics.crHandle = RGB(0,255,0);
   ContainerMetrics.nHandleHeight = 8;
   ContainerMetrics.nHandleWidth = 8;
   ContainerMetrics.fEnableHandles = TRUE;
   GetDocument()->m_Container.SetMetrics(&ContainerMetrics);

39.

Compile and run the program. Choose File->New from the menu bar. Choose View->Vector Toolbar. Select the line tool and draw several lines. Now select the "None" tool (with the arrow icon). Right-click on one of the vector lines. Handles appear. Drag one of the handles to rotate the line. Drag in the center of the line to move the entire line. Double click to end the "edit mode".