Implementing a Non-Automated Annotations Program (C++ 5.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, select the File New Project, and do the following:

    1. Expand Visual C++ tree, if it is not already expanded.
    2. Select MFC from the sub tree.
    3. Select MFC Application from the right window.
    4. In the Project name text box, specify Annotation.
    5. In the Location text box, specify the path of the project.
    6. Click the OK button.
  2. In the overview window Just click Next.

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

    1. Select Dialog based.
    2. Use MFC in a shared DLL.
    3. Click the Next button.
  4. In the Step 2 of 4 dialog box, do the following:

    1. Ensure that About Box is selected.
    2. Ensure that System Menu is selected.
    3. Click the Next button.
  5. In the Step 3 of 4 dialog box, Just click Finish:

  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 Solution Explorer tab.
    2. Double-click the Annotation Project folder to open it.
    3. Double-click the Header Files folder to open it.
    4. Double-click the StdAfx.h file to edit it.
  7. 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:

    1. In the Project Workspace, click the ResourceView tab.
    2. Double-click the Annotation.rc folder to open it.
    3. Double-click the Dialog folder to open it.
    4. Double-click IDD_ANNOTATION_DIALOG to design the form.
    5. Select the TODO... text control; then press the Delete key to delete it.
    6. 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:

    1. Right-click on the button then select properties.
    2. Set the Flat property to TRUE.
    3. Set the Owner Draw property to TRUE.
    4. Set the Visible property to TRUE.
    5. 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.

    1. In the Project Workspace, click the Solution Explorer tab.
    2. Double-click the Annotation folder to open it.
    3. Right-click the Source files folder and select Add New item.
    4. Right-click on the Source file.
    5. Expand Visual C++ tree, if it is not already expanded.
    6. Select Code from the sub tree.
    7. Select C++ File (.cpp) from the right window.
    8. In the name text box, specify Imports.
    9. Click the OK button.
    10. 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:

    1. From view menu, select Class view.
    2. In the Project Workspace, click the ClassView tab.
    3. Double-click the Annotationd folder to open it.
    4. Click on the CAnnotationDlg class.
    5. 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:

    1. In the Project Workspace, click the Project Explorer tab.
    2. Double-click the Annotation folder to open it.
    3. Double-click the Source files folder to open it.
    4. Double-click the AnnotationDlg.cpp file to edit it.
    5. 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.

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.