LAnnAutomation::SetAutoContainer

#include "ltwrappr.h"

virtual L_INT LAnnAutomation::SetAutoContainer(hContainer)

virtual L_INT LAnnAutomation::SetAutoContainer(pLContainer)

HANNOBJECT hContainer;

/* handle to the container */

LAnnContainer * pLContainer;

/* pointer to a container object */

Specifies the container for the Automation object. The automation object is used to implement default properties.

Parameter

Description

hContainer

Handle to the container.

pLContainer

Pointer to a container object.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function associates the automation object with a root container without inserting the object into the container.

Required DLLs and Libraries

LTANN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

LAnnAutomation::GetAutoContainer, LAnnAutomation::SetDpiX, LAnnAutomation::SetDpiY, LAnnAutomation::GetDpiX, LAnnAutomation::GetDpiY, LAnnAutomation::SetTool, LAnnAutomation::GetTool, LAnnotation::GetUserMode, LAnnContainer::SetUserMode, LAnnAutomation::SetUndoDepth, LAnnAutomation::Undo, Class Members, LAnnAutomation::SetAutoHilightPen, LAnnotation::SetAutoSnapCursor, LAnnotation::GetAutoSnapCursor, LAnnAutomation::GetAutoHilightPen

Topics:

Annotation Functions: Working with the Toolbar

 

Implementing Annotations

 

Automated User Interface for Annotations

 

Displaying and Manipulating Annotation Objects

Example

class MyAnnClass
{
   public :
      LAnnAutomation m_MyAutomation; //Automation object
      LAnnContainer m_MyContainer; //Container object
      LAnnToolBar m_MyToolbar; //Toolbar
      HWND m_hWnd; //Handle to this window 
      LBitmapBase m_MyBitmap; //Bitmap image to draw on
      /*Register a window class and create our main window*/
      /*Note that your window procedure must be static 
      (CALLBACK functions must be static or friend). I use extra bytes per window
      to hold the current object's pointer (this)
      */
   BOOL CreateWnd(HINSTANCE hInst, LPRECT pRect)
   {
      WNDCLASS wc;
      wc.style = CS_HREDRAW | CS_VREDRAW;
      wc.lpfnWndProc = MyWndProc; //static callback
      wc.cbClsExtra = 0;
      wc.cbWndExtra = sizeof(MyAnnClass  *); //In order to save this pointer
      wc.hInstance = hInst;
      wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
      wc.lpszMenuName = NULL;
      wc.lpszClassName = TEXT("MyAnnClass");
      if (RegisterClass(&wc)==0)
         return FALSE;
      m_hWnd= CreateWindow(TEXT("MyAnnClass"), NULL, 
                           WS_OVERLAPPEDWINDOW|WS_VISIBLE, 
                           pRect->left,pRect->top,
                           pRect->right,
                           pRect->bottom,
                           NULL,
                           (HMENU)NULL,
                           hInst,
                           NULL);
      //Attach the pointer to the window
      if (m_hWnd)
         L_SETWINDOWLONGPTR(m_hWnd, 0, this);
      return (m_hWnd!=NULL);
   }
   MyAnnClass(HINSTANCE hInst, L_TCHAR  * pszFileName)
   {
      if (m_MyBitmap.Load(pszFileName)==SUCCESS)
      {
         ANNRECT rcContainer ={0, 0, m_MyBitmap.GetWidth(), m_MyBitmap.GetHeight()};
         RECT rcClient ={0,0,640,480};
         POINT pt = {0,0};
         CreateWnd(hInst, &rcClient);
         m_MyContainer.Create(m_hWnd, &rcContainer, TRUE);
         m_MyContainer.SetScalarX((L_DOUBLE)rcClient.right/m_MyBitmap.GetWidth(),0);
         m_MyContainer.SetScalarY((L_DOUBLE)rcClient.bottom/m_MyBitmap.GetHeight(),0);
         m_MyContainer.SetOffsetX(0);
         m_MyContainer.SetOffsetY(0);
         m_MyContainer.SetUserMode(ANNUSER_DESIGN);
         //Assign the automation object to the container
         m_MyAutomation.SetAutoContainer(&m_MyContainer);
         m_MyAutomation.SetActiveState(ANNACTIVE_ENABLED);
         m_MyAutomation.SetDpiX(600);
         m_MyAutomation.SetDpiY(600);
         m_MyAutomation.SetUndoDepth(3);
         m_MyToolbar.Create(m_hWnd, &pt, ANNTOOLALIGN_LEFT | ANNTOOLALIGN_TOP, TRUE); 
      }
   }
   virtual ~MyAnnClass()
   {
      m_MyAutomation.SetActiveState(ANNACTIVE_DISABLED);
      m_MyAutomation.Destroy();
      m_MyContainer.Destroy();
      m_MyToolbar.Destroy(); 
   }
   static LRESULT CALLBACK MyWndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
   {
      MyAnnClass  * This = (MyAnnClass  *) L_GETWINDOWLONGPTR(hWnd, 0);
      if (This==NULL)
         return DefWindowProc(hWnd, uMsg, wParam, lParam);
      switch(uMsg)
      {
      case WM_PAINT:
         {
            PAINTSTRUCT ps;
            BeginPaint(hWnd,&ps);
            if (This->m_MyBitmap.IsAllocated())
            {
               This->m_MyBitmap.SetClipDstRect(&ps.rcPaint);
               This->m_MyBitmap.CreatePaintPalette(ps.hdc);
               This->m_MyBitmap.Paint()->SetDC(ps.hdc);
               This->m_MyBitmap.Paint()->PaintDC();
            }
            if (This->m_MyContainer.IsValid())
                  This->m_MyContainer.Draw(ps.hdc, &ps.rcPaint);
            EndPaint(hWnd, &ps);
         }
         break;
      case WM_SIZE:
         {
            if(This->m_MyContainer.IsCreated())
            {
               RECT rcDst;
               This->m_MyBitmap.GetRects(0,0,&rcDst,0);
               rcDst.right-=rcDst.left;
               rcDst.bottom-=rcDst.top;
               L_DOUBLE sx = (L_DOUBLE)((L_DOUBLE)(rcDst.right)/(L_DOUBLE)This->m_MyBitmap.GetWidth());
               L_DOUBLE sy = (L_DOUBLE)((L_DOUBLE)(rcDst.bottom)/(L_DOUBLE)This->m_MyBitmap.GetHeight());
               This->m_MyContainer.SetScalarX(sx,ANNFLAG_NOINVALIDATE);
               This->m_MyContainer.SetScalarY(sy,ANNFLAG_NOINVALIDATE);
               This->m_MyContainer.SetOffsetX(rcDst.left,ANNFLAG_NOINVALIDATE);
               This->m_MyContainer.SetOffsetY(rcDst.top,ANNFLAG_NOINVALIDATE);
            }
         }
         break;
      case WM_LTANNEVENT:
         if (wParam==LTANNEVENT_TOOLCHECKED)
            This->m_MyAutomation.SetTool((L_UINT)lParam);
         break;
      default:
         return DefWindowProc(hWnd, uMsg,wParam,lParam);
      }
      return FALSE;
   }
};
L_INT SetAutoContainerExample(HINSTANCE hInst)
{
   LBase::LoadLibraries(LT_ALL_LEADLIB);//make sure all libraries are loaded
   LBase::EnableAutoErrorDisplay(TRUE);
   UNLOCKSUPPORT();
   MyAnnClass MyAnnotationObject(hInst,TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\image1.cmp"));
   //loop till the user cancels the operation
   MSG msg;
   for (;;)
   {
      while (PeekMessage(&msg, NULL, 0,0, PM_REMOVE))
      {
         switch (msg.message)
         {
            case WM_KEYDOWN:
               if (msg.wParam != VK_ESCAPE)
                  break;
            case WM_QUIT:
               PostQuitMessage(0);
               return 0;
         }
         TranslateMessage(&msg);
         DispatchMessage(&msg); 
      }
   }
}