Implementing an Automated Annotations Program (C++ 6.0 and later)

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. Run Microsoft Visual Studio. From the main menu select the File -> New, and do the following:

    1. Make sure Projects tab is selected, if it is already not.
    2. Select MFC AppWizard(exe).
    3. In the Project name edit box, specify Automated.
    4. In the Location edit box, specify the path of the project.
    5. 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:

    1. Make sure About box checkbox is selected.
    2. Make sure 3D controls checkbox is selected.
    3. Make sure Automated is specified in the title edit box.
    4. Click the Next button.
  4. In MFC AppWizard - Step 3 of 4, do the following:

    1. Make sure MFC Standard radio button is selected.
    2. Make sure As a shared DLL radio button is selected.
    3. 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:

    1. In the Project Workspace, click the FileView tab.
    2. Expand the Automated files folder to view its contents.
    3. Expand the Header Files folder to view its contents.
    4. Double-click the StdAfx.h file to edit it.
    5. 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" 
    6. 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:

    1. From the main menu, select Project -> Settings...
    2. Select the C/C++ tab.
    3. Add the IGNORE_CLASSLIB_WIA flag to the end of text in Preprocessor definitions: edit box.
  8. Add a Button control to the main window as follows:

    1. In the Project Workspace, click the ResourceView tab.
    2. Expand the Automated resources folder to view its contents.
    3. Expand the Dialog folder to view its contents.
    4. Double-click IDD_AUTOMATED_DIALOG to design the form.
    5. Select the TODO... text control; then press the Delete key to delete it.
    6. 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:

    1. From General tab, set Visible property to FALSE.
    2. From Style tab, set Owner draw property to TRUE.
    3. From Style tab, set Flat property to TRUE.
    4. 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:

    1. From the main menu, select Insert -> New Class...
    2. In the Class Type combo box, select Generic class
    3. In the Class name edit box, specify CBitmapWindow
    4. Click on "Derived From" and type LBitmapWindow
    5. Click on "As" and specify public
    6. Click the OK button.
  13. Add #include statements to your program so you can access the LEAD C++ Class Library constants and classes:

    1. In the Project Workspace, click the FileView tab.
    2. Expand the Automated files folder to view its contents.
    3. Expand the Header Files folder to view its contents.
    4. Double-click the AutomatedDlg.h file to edit it.
    5. Add the following lines to the beginning of the file, after pragma once.
      #include "BitmapWindow.h" 
      #define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\LEADTOOLS23\\Resources\\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:

    1. In the Project Workspace, click the FileView tab.
    2. Expand the Automated files folder to view its contents.
    3. Expand the Source Files folder to view its contents.
    4. Double-click the BitmapWindow.cpp file to edit it.
    5. Add the following two lines in the CBitmapWindow::CBitmapWindow() constructor:

      m_pContainer = NULL; 
      m_pAutomation = NULL;   

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

    1. From the main menu, select File -> New.
    2. Select C++ Source File in the Files tab.
    3. 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\\CDLL\\x64\\Ltwvc_x.lib") 
             #else 
                #if _MSC_VER <=1200 
                   #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltwvc2_u.lib") 
                #else 
                   #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltwvc_u.lib") 
                #endif 
             #endif // #if defined(WIN64) 
          #else 
             #if defined(WIN64) 
                #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltwvc_ax.lib") 
             #else 
                #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\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:

    1. In the Project Workspace, click the ClassView tab.
    2. Expand the Automated classes folder to view its contents.
    3. Expand the CAutomatedDlg class to view its contents.
    4. 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.

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.