Implementing an 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 as follows: |
|
|
Run Microsoft Visual Studio 2005, 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 Automated. |
|
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 Automated 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 Automated.rc folder to open it. |
|
c. |
Double-click the Dialog folder to open it. |
|
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. |
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 FALSE. |
|
g. |
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 Project menu, select Add Class |
|
b. |
Expand Visual C++ tree, if it is not already expanded. |
|
c. |
Select C++ from the sub-tree. |
|
d. |
Select C++ Class from the right window. And press OK |
|
b. |
In the Class Type combo box, select Generic class |
|
c. |
In the Class name text box, specify CBitmapWindow |
|
d. |
Click on "Base class" and type LBitmapWindow |
|
e. |
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 Solution Explorer tab. |
|
b. |
Double-click the Automated folder to open it. |
|
c. |
Double-click the Header Files folder to open it. |
|
d. |
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"
14. |
Add the following Member Variables to the CBitmapWindow Class right after public: |
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 Solution Explorer tab. |
|
b. |
Double-click the Automated folder to open it. |
|
c. |
Double-click the Header files folder to open it. |
|
d. |
Double-click the BitmapWindow.cpp file to edit it. |
|
e. |
Add the following: |
CBitmapWindow::CBitmapWindow()
{
m_pContainer = NULL;
m_pAutomation = NULL;
}
CBitmapWindow::~CBitmapWindow()
{
}
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 in place it beside your project files. |
|
|
a. |
In the Project Workspace, click the Solution Explorer tab. |
|
b. |
Double-click the Automated 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)
17. |
Add the following Member Variables to CAutomatedDlg Class: |
|
|
LAnnContainer |
m_LeadAContainer; |
|
LAnnToolBar |
m_LeadAToolBar; |
|
HANNOBJECT |
hAutoObject; |
|
LAnnAutomation |
m_LeadAAutomation; |
|
CBitmapWindow |
m_LBitmap; |
18. |
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 Automated folder to open it. |
|
d. |
Click on the CAutomatedDlg class. |
|
e. |
Double-click the OnInitDialog()function in the lower window 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);
LSettings::UnlockSupport(L_SUPPORT_DOCUMENT, L_KEY_DOCUMENT);
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(TEXT("c:\\Program
Files\\LEAD Technologies\\LEADTOOLS 17\\Images\\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 AnnotationDlg.h file then add the following function declaration: |
afx_msg void OnClose();
21. |
Go to AnnotationDlg.cpp file then add the following line between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP: |
ON_WM_CLOSE()
22. |
Add the following function: |
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. |
On the main menu, select Build > Build Automated.exe to build the project. |
24. |
On the main menu, select Build > Execute Automated.exe to run the project. |