Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.10.24
LEADTOOLS Raster imaging C++ Class library help

Implementing a Non-Automated Annotations Program (C++ 5.0 and later)

Show in webframe

Take the following steps to start a project and to add some code that positions, scales, and displays an image in a dialog box.

1.

Start a new project as follows:

 

Run Microsoft Visual Studio, select the File New Project, and do the following:

 

a.

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

 

b.

Select MFC from the sub tree.

 

c.

Select MFC Application from the right window.

 

d.

In the Project name text box, specify Annotation.

 

e.

In the Location text box, specify the path of the project.

 

f.

Click the OK button.

2.

In the overview window Just click Next.

3.

In the Application Type step dialog box, do the following:

 

a.

Select Dialog based.

 

b.

Use MFC in a shared DLL

 

c.

Click the Next button.

3.

In the Step 2 of 4 dialog box, do the following:

 

a.

Ensure that About Box is selected.

 

b.

Ensure that System Menu is selected.

 

c.

Click the Next button.

4.

In the Step 3 of 4 dialog box, Just click Finish:

5.

Add #include statements to your program so you can access the LEAD C++ Class Library constants and classes:

 

a.

In the Project Workspace, click the Solution Explorer tab.

 

b.

Double-click the Annotation Project folder to open it.

 

c.

Double-click the Header Files folder to open it.

 

d.

Double-click the StdAfx.h file to edit it.

 

Add the following lines to the end of the file (keep in mind, you may have to change the path to where the header files reside):

#include "..\..\..\..\..\include\ClassLib\ltWrappr.h"

8.

Add a Button control to the main window as follows:

 

a.

In the Project Workspace, click the ResourceView tab.

 

b.

Double-click the Annotation.rc folder to open it.

 

c.

Double-click the Dialog folder to open it.

 

d.

Double-click IDD_ANNOTATION_DIALOG to design the form.

 

e.

Select the TODO... text control; then press the Delete key to delete it.

 

f.

Click the Button control icon; then size and position the control as you want it to appear at run time.

 

9.

From View menu, select ToolBox, and from the ToolBox Window add a command button to your form and name it as follows:

 

ID

Caption

 

IDC_BITMAPWND

Bitmap Window

 

10.

Change the command button properties as follows:

 

a.

Right-click on the button then select properties.

 

c.

Set the Flat property to TRUE.

 

d.

Set the Owner Draw property to TRUE.

 

f.

Set the Visible property to TRUE.

 

g.

Save the changes.

11.

Press Ctrl-F4 to close all windows back to the Project Workspace.

 

12.

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

a.

In the Project Workspace, click the Solution Explorer tab.

b.

Double-click the Annotation 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 import.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)

 

13.

Add the following Member Variables to CAnnotationDlg Class:

 

LAnnContainer

m_LeadAContainer;

 

LPaint

m_LPaint;

 

LBitmap

m_LBitmap;

 

void

CreateNoteAnn(HWND hWnd);

 

void

AnnStart(HWND hWnd);

 

14.

Go to the OnInitDialog() function as follows:

 

a.

From view menu, select Class view.

 

b.

In the Project Workspace, click the ClassView tab.

 

c.

Double-click the Annotationd folder to open it.

 

d.

Click on the CAnnotationDlg class.

 

e.

Double-click the OnInitDialog()function in the lower window to edit it.

15.

Edit the OnInitDialog() function to add the following code after the line that says //TODO: Add extra initialization here:

 

LSettings::LoadLibraries (LT_ALL_LEADLIB);

L_TCHAR * pszLicenseFile = L"Replace this with the path to the LEADTOOLS license file";
L_TCHAR * pszDeveloperKey = L"Replace this with your developer key";
LSettings::SetLicenseFile(pszLicenseFile, pszDeveloperKey);
 

16.

Add implementation to the member method in the CAnnotationDlg class:

 

a.

In the Project Workspace, click the Project Explorer tab.

 

b.

Double-click the Annotation folder to open it.

 

c.

Double-click the Source files folder to open it.

 

d.

Double-click the AnnotationDlg.cpp file to edit it.

 

e.

Add the following to the end of the file:

void CAnnotationDlg::AnnStart(HWND hWnd)
{
   RECT rcClientArea;
   ANNRECT rcContainerRect;
   HDC hDC;

   m_LBitmap.Load(MAKE_IMAGE_PATH(TEXT("image1.cmp")));

   ::GetClientRect(hWnd,&rcClientArea);
   m_LBitmap.SetDstRect(&rcClientArea);

   hDC = ::GetDC(hWnd);

   /*Display our Bitmap*/
   m_LPaint.SetBitmap(&m_LBitmap);
   m_LPaint.SetDC(hDC);
   m_LPaint.PaintDC();

   ::ReleaseDC(hWnd,hDC);

   // Create Container
   rcContainerRect.left = 0;
   rcContainerRect.top = 0;
   rcContainerRect.right = rcClientArea.right-rcClientArea.left;
   rcContainerRect.bottom = rcClientArea.bottom-rcClientArea.top;

   m_LeadAContainer.Create(hWnd,&rcContainerRect,TRUE);

   m_LeadAContainer.SetOffsetX((L_DOUBLE) 0, 0);
   m_LeadAContainer.SetOffsetY((L_DOUBLE) 0, 0);
}

void CAnnotationDlg::CreateNoteAnn(HWND hWnd)
{
   LAnnNote AnnNote;
   RECT rcAnnBounds;
   HDC hDC;
   ANNRECT rcContainerRect;
   ANNRECT rcNoteRect;

   hDC = ::GetDC(hWnd); 

   m_LeadAContainer.GetRect(&rcContainerRect);
   int nRet = AnnNote.Create();

   /* Size and position the note */
   rcNoteRect.left = rcContainerRect.right / 8;
   rcNoteRect.top = rcContainerRect.bottom / 8;
   rcNoteRect.right = rcContainerRect.right / 2;
   rcNoteRect.bottom = rcContainerRect.bottom / 2;

   nRet = AnnNote.SetRect(&rcNoteRect);

   nRet = AnnNote.SetText(TEXT("This is my text"), 0);
   nRet = AnnNote.SetBackColor(RGB(0, 255, 255), 0);
   nRet = AnnNote.SetFontBold(TRUE, 0);
   AnnNote.SetFontItalic (FALSE, 0);
   AnnNote.SetFontName (TEXT("Arial"), 0);
   AnnNote.SetFontSize (16, 0);
   AnnNote.SetFontStrikeThrough(FALSE, 0);
   AnnNote.SetFontUnderline(TRUE, 0);
   AnnNote.SetForeColor (RGB(255, 0, 0), 0);

   /* Display the note */

   AnnNote.SetVisible(TRUE);
   nRet = m_LeadAContainer.Insert(AnnNote);

   nRet = m_LeadAContainer.GetBoundingRect(&rcAnnBounds, NULL);
   nRet = m_LeadAContainer.Draw(hDC,&rcAnnBounds);
  ::ReleaseDC(hWnd,hDC);
}

17.

Add a Button to your form and name it as follows:

 

ID

Caption

 

IDC_STARTANN

&Start Annotation

 

 

 

 

18.

Double-click the Start Annotation button to generate the message handler, and code it as follows:

void CAnnotationDlg::OnBnClickedStartann()
{
AnnStart(GetDlgItem(IDC_BITMAPWND)->GetSafeHwnd());
CreateNoteAnn(GetDlgItem(IDC_BITMAPWND)->GetSafeHwnd());
}

19.

Go to AnnotationDlg.h file then add the following function declaration:

afx_msg void OnClose(); 

 

20.

Go to AnnotationDlg.cpp file then add the following line between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP:

ON_WM_CLOSE()

 

21.

Add the following function:

void CAnnotationDlg::OnClose()
{
   if (m_LBitmap.IsAllocated())
   {
      m_LBitmap.Free();
   }
CDialog::OnClose();
}

 

22.

On the main menu, select Build > Build Automated.exe to build the project.

23.

On the main menu, select Build > Execute Automated.exe to run the project.

Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.