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, select the File New Project, and do the following:
In the overview window Just click Next.
In the Application Type step dialog box, do the following:
In the Step 2 of 4 dialog box, do the following:
In the Step 3 of 4 dialog box, Just click Finish:
Add #include statements to your program so you can access the LEAD C++ Class Library constants and classes:
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"
Add a Button control to the main window as follows:
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 |
Change the command button properties as follows:
Press Ctrl-F4 to close all windows back to the Project Workspace.
Create a new file called Imports.cpp in place it beside your project files.
#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)
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);
Go to the OnInitDialog() function as follows:
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);
Add implementation to the member method in the CAnnotationDlg class:
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);
}
Add a Button to your form and name it as follows:
ID | Caption |
---|---|
IDC_STARTANN | &Start Annotation |
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());
}
Go to AnnotationDlg.h file then add the following function declaration:
afx_msg void OnClose();
Go to AnnotationDlg.cpp file then add the following line between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP:
ON_WM_CLOSE()
Add the following function:
void CAnnotationDlg::OnClose()
{
if (m_LBitmap.IsAllocated())
m_LBitmap.Free();
CDialog::OnClose();
}
On the main menu, select Build > Build Automated.exe to build the project.
On the main menu, select Build > Execute Automated.exe to run the project.
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document