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 an Automated Annotations Program (C++ 6.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. From the main menu select the File -> New, and do the following:

 

a.

Make sure Projects tab is selected, if it is already not.

 

b.

Select MFC AppWizard(exe).

 

c.

In the Project name edit box, specify Automated.

 

d.

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

 

e.

Click the OK button.

2.

In MFC AppWizard - Step1 select Dialog based as application type then click Next.

3.

In MFC AppWizard - Step 2 of 4, do the following:

 

a.

Make sure About box checkbox is selected.

 

b.

Make sure 3D controls checkbox is selected.

 

c.

Make sure ActiveX Controls checkbox is selected.

 

d.

Make sure Automated is specified in the title edit box.

 

e.

Click the Next button.

4.

In MFC AppWizard - Step 3 of 4, do the following:

 

a.

Make sure MFC Standard radio button is selected.

 

b.

Make sure As a shared DLL radio button is selected.

 

c.

Click the Next button.

5.

In MFC AppWizard - Step 4 of 4, click the Finish button.

6.

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 FileView tab.

 

b.

Expand the Automated files folder to view it's contents.

 

c.

Expand the Header Files folder to view it's contents.

 

d.

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

 

e.

Add the following line 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"

 

 

f.

Add the following define statement after #define VC_EXTRALEAN (keep in mind, you need to change the XX to your current LEADTOOLS version):

 

#define LTVXX_CONFIG
 

7.

Add the following setting to the project as follows:

 

a.

From the main menu, select Project -> Settings...

 

b.

Select the C/C++ tab.

 

c.

Add the IGNORE_CLASSLIB_WIA flag to the end of the text in Preprocessor definitions: edit box.

 

8.

Add a Button control to the main window as follows:

 

a.

In the Project Workspace, click the ResourceView tab.

 

b.

Expand the Automated resources folder to view it's contents.

 

c.

Expand the Dialog folder to view it's contents.

 

d.

Double-click IDD_AUTOMATED_DIALOG to design the form.

 

e.

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

 

f.

From Controls context menu, click the Button control icon; then size and position the control as you want it to appear at run time.

 

9.

Right-click the newly created button and select Properties. In the General tab specify the following:

 

ID

Caption

 

IDC_BITMAPWND

Bitmap Window

 

10.

Change the command button properties as follows:

 

a.

From General tab, set Visible property to FALSE.

 

b.

From Style tab, set Owner draw property to TRUE.

 

c.

From Style tab, set Flat property to TRUE.

 

d.

Save the changes.

11.

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

 

12.

Add a new class to the project as follows -- this class will be inherited from the LBitmapWindow class:

 

a.

From the main menu, select Insert -> New Class...

 

b.

In the Class Type combo box, select Generic class

 

c.

In the Class name edit box, specify CBitmapWindow

 

d.

Click on "Derived From" and type LBitmapWindow

 

e.

Click on "As" and specify public

 

f.

Click the OK button.

13.

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 FileView tab.

 

b.

Expand the Automated files folder to view it's contents.

 

c.

Expand the Header Files folder to view it's contents.

 

d.

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

 

e.

Add the following lines to the beginning of the file, after pragma once.

 

#include "BitmapWindow.h"
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
 

14.

Add the following Member Variables to the CBitmapWindow Class right after public section:

 

   LRESULT MsgProcCallBack(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
  L_VOID SetContainer(LAnnContainer * pContainer);
  L_VOID SetAutomation(LAnnAutomation * pAutomation);
  L_VOID SetToolBar(LAnnToolBar * pToolBar);
  L_VOID OnDraw(HDC hdc, RECT & Rect);
   

private:
  LAnnContainer* m_pContainer;
  LAnnAutomation *m_pAutomation;
  LAnnToolBar *m_pToolBar;
 

15.

Add implementation to the member method in CBitmapWindow class:

 

a.

In the Project Workspace, click the FileView tab.

 

b.

Expand the Automated files folder to view it's contents.

 

c.

Expand the Source Files folder to view it's contents.

 

d.

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

 

e.

Add the following two lines in the CBitmapWindow::CBitmapWindow() constructor:

 

   m_pContainer = NULL;
   m_pAutomation = NULL;

 

 

f.

Add the following code after the CBitmapWindow::~CBitmapWindow() destructor:

 

L_VOID CBitmapWindow::SetContainer(LAnnContainer * pContainer)
{
   m_pContainer = pContainer;
}

L_VOID CBitmapWindow::SetAutomation(LAnnAutomation * pAutomation)
{
   m_pAutomation = pAutomation;
}

L_VOID CBitmapWindow::SetToolBar(LAnnToolBar * pToolBar)
{
   m_pToolBar = pToolBar;
}

L_VOID CBitmapWindow::OnDraw (HDC hdc, RECT & Rect)
{
   LBitmapWindow::OnDraw(hdc, Rect);
   L_INT nRet;   
   if (m_pContainer != NULL)
   {      
      nRet = m_pContainer->Draw(hdc, &Rect);   
   }      

}

LRESULT CBitmapWindow::MsgProcCallBack(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
   switch (uMsg)
   {
   case WM_LTANNEVENT:
      if(m_pAutomation != NULL)
      {
            int uChecked = m_pToolBar->GetToolChecked() ;
            m_pAutomation->SetTool(uChecked);
      }
      break;
   };

   return LBitmapWindow::MsgProcCallBack(hWnd,uMsg,wParam,lParam);
}

 

16.

Create a new file called Imports.cpp and place it in Source Files folder in your project.

 

a.

From the main menu, select File -> New.

 

b.

Select C++ Source File in the Files tab.

 

c.

Make sure that Add to project: checkbox is checked, and type Imports.cpp in the File name: edit box, then click OK.

 

#include "StdAfx.h"
#if defined(LEADTOOLS_V18_OR_LATER)
#if defined(FOR_UNICODE)
 #if defined(WIN64)
    #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLLVC10\\x64\\Ltwvc_x.lib")
 #else
    #if _MSC_VER <=1200
       #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLLVC10\\Win32\\Ltwvc2_u.lib")
    #else
       #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLLVC10\\Win32\\Ltwvc_u.lib")
    #endif
 #endif // #if defined(WIN64)
#else
 #if defined(WIN64)
    #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLLVC10\\x64\\Ltwvc_ax.lib")
 #else
    #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLLVC10\\Win32\\Ltwvc_a.lib")
 #endif // #if defined(WIN64)
#endif // #if defined(FOR_UNICODE)
#else
 #if defined(FOR_UNICODE)
    #if defined(WIN64)
       #pragma comment(lib, "..\\..\\..\\..\\Lib\\"L_PLATFORM_DESIGNATOR"\\x64\\Ltwvc_x.lib")
    #else
       #if _MSC_VER <=1200
          #pragma comment(lib, "..\\..\\..\\..\\Lib\\"L_PLATFORM_DESIGNATOR"\\Win32\\Ltwvc2_u.lib")
       #else
          #pragma comment(lib, "..\\..\\..\\..\\Lib\\"L_PLATFORM_DESIGNATOR"\\Win32\\Ltwvc_u.lib")
       #endif
    #endif // #if defined(WIN64)
 #else
    #if defined(WIN64)
       #pragma comment(lib, "..\\..\\..\\..\\Lib\\"L_PLATFORM_DESIGNATOR"\\x64\\Ltwvc_ax.lib")
    #else
       #pragma comment(lib, "..\\..\\..\\..\\Lib\\"L_PLATFORM_DESIGNATOR"\\Win32\\Ltwvc_a.lib")
    #endif // #if defined(WIN64)
 #endif // #if defined(FOR_UNICODE)
#endif // #if defined(LEADTOOLS_V18_OR_LATER)

 

17.

Add the following Member Variables to CAutomatedDlg Class in the header file AutomatedDlg.h:

 

   LAnnContainer m_LeadAContainer;
  LAnnToolBar m_LeadAToolBar;
  HANNOBJECT hAutoObject;
  LAnnAutomation m_LeadAAutomation;
  CBitmapWindow m_LBitmap;

 

18.

Go to the OnInitDialog() function as follows:

 

a.

In the Project Workspace, click the ClassView tab.

 

b.

Expand the Automated classes folder to view it's contents.

 

c.

Expand the CAutomatedDlg class to view it's contents.

 

d.

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

19.

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_TCHAR *)L"Replace this with the path to the LEADTOOLS license file";
L_TCHAR * pszDeveloperKey = (L_TCHAR *)L"Replace this with your developer key";
LSettings::SetLicenseFile(pszLicenseFile, pszDeveloperKey);
   
CWnd* pWnd = GetDlgItem(IDC_BITMAPWND);
// m_LBitmap.SetWndHandle(hWnd);*/
m_LBitmap.EnableAutoScroll(FALSE);
   
CRect rcRect;
// Get the rectangle of the button
pWnd->GetWindowRect(&rcRect);
ScreenToClient(&rcRect);

// Create the LBitmapWindow control, make it visible, and make it center the image
HWND hWnd = m_LBitmap.CreateWnd(GetSafeHwnd(), 901, WS_VISIBLE|L_BS_CENTER|WS_HSCROLL, rcRect.TopLeft().x, rcRect.TopLeft().y, rcRect.BottomRight().x, rcRect.BottomRight().y);

int nRet = 0;
RECT rcClientArea;
ANNRECT rcContainerRect;

nRet = m_LBitmap.Load(MAKE_IMAGE_PATH(TEXT("image1.cmp")));
if(nRet == SUCCESS)
{
   ::GetClientRect(hWnd,&rcClientArea);
   m_LBitmap.SetDstRect(&rcClientArea);

   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);
   
   m_LeadAAutomation.Create();
 
   /* Assign the automation object to the container */
   m_LeadAAutomation.SetAutoContainer(&m_LeadAContainer);

   /* Enable the automation object */
   m_LeadAAutomation.SetActiveState(ANNACTIVE_ENABLED);

   /* Set design mode, which allows creation of annotations */
   m_LeadAContainer.SetUserMode();

   /* Set the dots per inch for interpreting physical measurements */
   m_LeadAContainer.SetDpiX(600, 0);
   m_LeadAContainer.SetDpiY(600, 0);

   /* Set the number of possible undo actions */
   m_LeadAAutomation.SetUndoDepth(3);

   /* Set the line tool as the initial annotation tool */

   m_LeadAToolBar.Create(this->GetSafeHwnd(), NULL, ANNTOOLALIGN_RIGHT | ANNTOOLALIGN_TOP, TRUE);
   
   m_LBitmap.SetContainer(&m_LeadAContainer);
   m_LBitmap.SetAutomation(&m_LeadAAutomation);
   m_LBitmap.SetToolBar(&m_LeadAToolBar);
}

20.

Go to AutomatedDlg.h file then add the following function declaration right before DECLARE_MESSAGE_MAP():

 

afx_msg void OnClose();
 

21.

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

 

ON_WM_CLOSE()
 

22.

Add the following function to the end of AutomatedDlg.cpp file:

 

void CAutomatedDlg::OnClose()
{
   if(m_LBitmap.IsAllocated())
   {
      m_LBitmap.Free();
      m_LBitmap.SetContainer(NULL);
      m_LBitmap.SetAutomation(NULL);
      m_LBitmap.SetToolBar(NULL);
      m_LeadAAutomation.SetActiveState(ANNACTIVE_DISABLED);
      m_LeadAAutomation.Destroy ();
      m_LeadAContainer.Destroy();
      m_LeadAToolBar.Destroy();
   }

 CDialog::OnClose();
}
 

23.

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

24.

From 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.