Implementing an Automated Annotations Program (C++ 6.0 and later) (original) (raw)
Take the following steps to start a project and to add some code that positions, scales, and displays an image in a dialog box.
- Start a new project. Run Microsoft Visual Studio. From the main menu select the File -> New, and do the following:
- Make sure Projects tab is selected, if it is already not.
- Select MFC AppWizard(exe).
- In the Project name edit box, specify Automated.
- In the Location edit box, specify the path of the project.
- Click the OK button.
- In MFC AppWizard - Step1 select Dialog based as application type then click Next.
- In MFC AppWizard - Step 2 of 4, do the following:
- Make sure About box checkbox is selected.
- Make sure 3D controls checkbox is selected.
- Make sure Automated is specified in the title edit box.
- Click the Next button.
- In MFC AppWizard - Step 3 of 4, do the following:
- Make sure MFC Standard radio button is selected.
- Make sure As a shared DLL radio button is selected.
- Click the Next button.
- In MFC AppWizard - Step 4 of 4, click the Finish button.
- Add #include statements to your program so you can access the LEAD C++ Class Library constants and classes:
- In the Project Workspace, click the FileView tab.
- Expand the Automated files folder to view its contents.
- Expand the Header Files folder to view its contents.
- Double-click the StdAfx.h file to edit it.
- 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"
- Add the following define statement after #define VC_EXTRALEAN (keep in mind, you need to change the XX to your current LEADTOOLS version):
- Add the following setting to the project as follows:
- From the main menu, select Project -> Settings...
- Select the C/C++ tab.
- Add the IGNORE_CLASSLIB_WIA flag to the end of text in Preprocessor definitions: edit box.
- Add a Button control to the main window as follows:
- In the Project Workspace, click the ResourceView tab.
- Expand the Automated resources folder to view its contents.
- Expand the Dialog folder to view its contents.
- Double-click IDD_AUTOMATED_DIALOG to design the form.
- Select the TODO... text control; then press the Delete key to delete it.
- From Controls context menu, click the Button control icon; then size and position the control as you want it to appear at run time.
- Right-click the newly created button and select Properties. In the General tab specify the following:
ID Caption IDC_BITMAPWND Bitmap Window - Change the command button properties as follows:
- From General tab, set Visible property to FALSE.
- From Style tab, set Owner draw property to TRUE.
- From Style tab, set Flat property to TRUE.
- Save the changes.
- Press Ctrl-F4 to close all windows back to the Project Workspace.
- Add a new class to the project as follows -- this class will be inherited from the LBitmapWindow class:
- From the main menu, select Insert -> New Class...
- In the Class Type combo box, select Generic class
- In the Class name edit box, specify CBitmapWindow
- Click on "Derived From" and type LBitmapWindow
- Click on "As" and specify public
- Click the OK button.
- Add #include statements to your program so you can access the LEAD C++ Class Library constants and classes:
- In the Project Workspace, click the FileView tab.
- Expand the Automated files folder to view its contents.
- Expand the Header Files folder to view its contents.
- Double-click the AutomatedDlg.h file to edit it.
- Add the following lines to the beginning of the file, after pragma once.
#include "BitmapWindow.h"
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\LEADTOOLS22\\Resources\\Images\\")pFileName
- 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;
- Add implementation to the member method in CBitmapWindow class:
- In the Project Workspace, click the FileView tab.
- Expand the Automated files folder to view its contents.
- Expand the Source Files folder to view its contents.
- Double-click the BitmapWindow.cpp file to edit it.
- Add the following two lines in the CBitmapWindow::CBitmapWindow() constructor:
m_pContainer = NULL;
m_pAutomation = NULL;
- 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.
- From the main menu, select File -> New.
- Select C++ Source File in the Files tab.
- 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:
- In the Project Workspace, click the ClassView tab.
- Expand the Automated classes folder to view its contents.
- Expand the CAutomatedDlg class to view its contents.
- Double-click the OnInitDialog() function to edit it.
- 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);
}
- Go to AutomatedDlg.h file then add the following function declaration right before DECLARE_MESSAGE_MAP():
- Go to AutomatedDlg.cpp file then add the following line between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP:
- 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();
}
- From the main menu, select Build -> Build Automated.exe to build the project.
- From the main menu, select Build -> Execute Automated.exe to run the project.
LEADTOOLS Raster Imaging C++ Class Library Help