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 as follows: | |
|
Run Microsoft Visual C++ 5.0, select the File >New menu option, and do the following: | |
|
a. |
Click the Projects tab. |
|
b. |
Select MFC AppWizard (exe) as the project type |
|
c. |
In the Project name text box, specify Annotation. |
|
d. |
In the Location text box, specify the path of the project. |
|
e. |
Click the OK button. |
2. |
In the Step 1 dialog box, do the following: | |
|
a. |
Select Dialog based. |
|
b. |
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 3D Controls is selected. |
|
c. |
Click the Next button. |
4. |
In the Step 3 of 4 dialog box, do the following: | |
|
a. |
For comments, ensure that Yes, Please is selected. |
|
b. |
For how to use the MFC library, select Use MFC in a Shared DLL. |
|
c. |
Click the Next button. |
5. |
In the Step 4 of 4 dialog box, just click Finish. | |
6. |
Read New Project Information, and click OK. (The AppWizard creates the project files and opens the project.) | |
7. |
Add #include statements to your program so you can access the LEAD Class Library constants and classes: | |
|
a. |
In the Project Workspace, click the FileView tab. |
|
b. |
Double-click the Annotation files 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 Annotation resources folder to open it. |
|
c. |
Double-click the Dialog folder to open it. |
|
d. |
Double-click IDD_ANNOTATION_DIALOG to design the form. |
|
e. |
Select the TODO... text control; then press the Delete key to delete it. |
9. |
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. |
|
b. |
Click the Styles tab. |
|
c. |
Select the Flat check box |
|
d. |
Select the Owner Draw check box |
|
e. |
Click the General tab. |
|
f. |
Clear the Visible check box |
|
g. |
Close the dialog |
11. |
Press Ctrl-F4 to close all windows back to the Project Workspace. |
12. |
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); |
13. |
Go to the OnInitDialog() function as follows: | |
|
a. |
In the Project Workspace, click the ClassView tab. |
|
b. |
Double-click the Annotation classes folder to open it. |
|
c. |
Expand the CAnnotationDlg class. |
|
d. |
Double-click the OnInitDialog() function to edit it. |
14. |
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);
15. |
Add implementation to the member method in the CAnnotationDlg class: | |
|
a. |
In the Project Workspace, click the FileView tab. |
|
b. |
Double-click the Annotation files folder to open it. |
|
c. |
Double-click the Source files folder to open it. |
|
d. |
Double-click the AnnotationDlg.cpp file to edit it. |
|
e. |
Add the following to the end of the file: |
void CAnnotationDlg::AnnStart(HWND hWnd)
{
RECT rcClientArea;
ANNRECT rcContainerRect;
HDC hDC;
m_LBitmap.Load(TEXT("c:\\parrots.jpg"));
::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);
}
16. |
Add a command control to your from and name it as follows: | |
|
ID |
Caption |
|
IDC_STARTANN |
&Start Annotation |
17. |
Press Ctrl-W to go to the MFC Class Wizard; then do the following: | |
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CAnnotationDlg. |
|
c. |
In the Object IDs list box, select IDC_STARTANN. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnStartANN). |
|
f. |
Click the Edit Code button and enter the following code: |
AnnStart(GetDlgItem(IDC_BITMAPWND)->GetSafeHwnd());
CreateNoteAnn(GetDlgItem(IDC_BITMAPWND)->GetSafeHwnd());
18. |
On the main menu, select Build > Build Annotation.exe to build the project. |
19. |
On the main menu, select Build > Execute Annotation.exe to run the project. |