Adding Annotations through a User Interface

Developers can add an annotation object to an image programmatically or with user interaction. The user can use the mouse to create new annotation objects and place them on the image. The user can move, resize, or delete annotation objects.  Developers have to redefine mouse event handler functions to create new annotation objects with the mouse.

 

[C++]

 

#include “BiAnno.h”

#include “BiDisp.h”

 

void CMyView::OnLButtonDown(UINT nFlags, CPoint point)

{

        …

        ::SetCapture( m_hWnd );

        POINT pt;

        pt.x = point.x;

        pt.y = point.y;

 

        CDC * pDC = GetDC();

        MapDisplayDC(pDC->m_hDC, lpDisp);

        pDC->DPtoLP( &pt, 1);

 

        // lAnno is the annotation handle

         if(AnnoUIOnLButtonDown ( lAnno, pDC->m_hDC, nFlags, pt ) )

            UpdateSelectionRect();

        ReleaseDC(pDC);

        …

}

 

void CMyView::OnMouseMove(UINT nFlags, CPoint point)

{

        …

        POINT pt;

        pt.x = point.x;

        pt.y = point.y;

 

        CDC * pDC = GetDC();

        MapDisplayDC(pDC->m_hDC, lpDisp);

        pDC->DPtoLP( &pt, 1);

 

        // lAnno is the annotation handle

        AnnoUIOnMouseMove (lAnno, pDC->m_hDC, nFlags, pt );

        ReleaseDC(pDC);

        …

}

 

void CMyView::OnLButtonUp(UINT nFlags, CPoint point)

{

        …

        ::ReleaseCapture();

        POINT pt;

        pt.x = point.x;

        pt.y = point.y;

 

        CDC * pDC = GetDC();

         MapDisplayDC(pDC->m_hDC, lpDisp);

        pDC->DPtoLP( &pt, 1);

 

         // lAnno is the annotation handle

         if(AnnoUIOnLButtonUp(lAnno, pDC->m_hDC, nFlags, pt ) )

                   UpdateSelectionRect();

         ReleaseDC(pDC);

        …

}

 

You can call the AnnoUISetNewObject function to create a new annotation object, and use the mouse to place the newly created object on the image.

 

[C#]

 

private void BiDisp_MouseDownEvent(object sender, AxBIDISPLib._DBIDispEvents_MouseDownEvent e)

{

         …

         BiDisp.SetCapture();

         long hDC = BiDisp.GetDC();

         int Left = 0, Right = 0, Top = 0, Bottom = 0;

         bool ret = BiAnno.OnMouseDown(hDC, e.button, e.shift, BiDisp.MouseX,

                                    BiDisp.MouseY);

         BiDisp.ReleaseDC(hDC);

         if (ret)

         {

               BiAnno.AnnoUIGetUpdateRect(ref Left, ref Top, ref Right, ref Bottom);

               BiDisp.UpdateControl(Left, Top, Right, Bottom);

         }

         …

}

 

private void BiDisp_MouseMoveEvent(object sender, AxBIDISPLib._DBIDispEvents_MouseMoveEvent e)

{

         …

         long hDC = BiDisp.GetDC();

         BiAnno.OnMouseMove(hDC, e.button, e.shift, BiDisp.MouseX, BiDisp.MouseY);

         BiDisp.ReleaseDC(hDC);

         …

}

 

private void BiDisp_MouseUpEvent(object sender, AxBIDISPLib._DBIDispEvents_MouseUpEvent e)

{

         …

         bool ret = false;

         BiDisp.ReleaseCapture();

         ret = BiAnno.OnMouseUp(hDC, e.button, e.shift, BiDisp.MouseX,

                        BiDisp.MouseY);

         BiDisp.ReleaseDC(hDC);

         if (ret)

         {

             BiAnno.AnnoUIGetUpdateRect(ref Left, ref Top, ref Right, ref Bottom);

              BiDisp.UpdateControl(Left, Top, Right, Bottom);

         }

         …

}

 

You can call the AnnoUISetNewObject method to create a new annotation object, and use the mouse to place the newly created object on the image.