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:
In MFC AppWizard - Step1 select Dialog based as application type then click Next.
In MFC AppWizard - Step 2 of 4, do the following:
In MFC AppWizard - Step 3 of 4, do the following:
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:
#include "..\..\..\..\..\Include\ClassLib\ltWrappr.h"
#define LTVXX_CONFIG
Add the following setting to the project as follows:
Add a Button control to the main window as follows:
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:
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:
Add #include statements to your program so you can access the LEAD C++ Class Library constants and classes:
#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:
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);
}
Create a new file called Imports.cpp and place it in Source Files folder in your project.
#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)
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;
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_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():
afx_msg void OnClose();
Go to AutomatedDlg.cpp file then add the following line between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP:
ON_WM_CLOSE()
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.
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