Take the following steps to start a project and to add some code that acquires the images using the LEADTOOLS Fast TWAIN features:
Examples\Scanning\ClassLibrary
directory of your LEAD installation. For example, if you installed LEADTOOLS in C:\LEADTOOLS22\
, enter C:\LEADTOOLS22\Examples\Scanning\ClassLibrary
, then Click OK. Then click Next.FastTwainTutor.h
.Add the following line immediately before the class CFastTwainTutorApp
declaration (keep in mind, you may have to change the path to where the header files reside):
#include "..\..\..\..\include\ClassLib\ltwrappr.h"
Click the Class View tab.
Add the following lines after //TODO: add construction code here
:
LBase::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);
Create a new file called Imports.cpp
and place it beside your project files.
FastTwainTutor
folder to open it.Source
files folder and select Add New item.Imports.cpp
imports.cpp
in the Solution Explorer and add the following lines:
#include "StdAfx.h"
#if defined(WIN64)
#else
#pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltwvc_u.lib")
#endif // #if defined(WIN64)
Click the Solution Explorer tab.
FastTwainTutorDlg.h
file to open it.Add the following class declaration before the CFastTwainTutorDlg
class.
class LMyTwain : public LTwain
{
LEAD_DECLAREOBJECT(LMyTwain);
public:
LMyTwain();
virtual ~LMyTwain();
virtual L_INT BitmapCallBack(pBITMAPHANDLE pBitmap);
};
Click the Solution Explorer tab.
FastTwainTutor
folder to open it.Source Files
folder to open it. Then double-click FastTwainTutorDlg.cpp
file to open it.Add the following class:
LEAD_IMPLEMENTOBJECT(LMyTwain);
LMyTwain::LMyTwain()
{
EnableCallBack(TRUE);
}
LMyTwain::~LMyTwain()
{
}
L_INT LMyTwain::BitmapCallBack(pBITMAPHANDLE pBitmap)
{
//Copy the acquired bitmap here
return SUCCESS;
}
Click the Class View tab.
LMyTwain
, and for Variable Declaration put m_MyTwain
. Leave Access as Public and click OK.Click to open the CFastTwainTutorDlg
branch. Double click the OnInitDialog()
function and add the following code after line:
// TODO: Add extra initialization here
APPLICATIONDATA AppData;
memset(&AppData, 0, sizeof(APPLICATIONDATA));
AppData.hWnd = m_hWnd;
AppData.uStructSize = sizeof(AppData);
lstrcpy(AppData.szManufacturerName, _T("LEAD Technologies, Inc."));
lstrcpy(AppData.szAppProductFamily, _T("LEAD Test Applications"));
lstrcpy(AppData.szVersionInfo, _T("Version 1.0"));
lstrcpy(AppData.szAppName, _T("TWAIN Test Application"));
m_MyTwain.InitSession(&AppData);
Right-click the CFastTwainTutorDlg
branch, and choose Properties.
WM_DESTROY
and choose OnDestroy
.Add the following code after the opening bracket {
:
m_MyTwain.EndSession();
LBase::UnloadLibraries(LT_ALL_LEADLIB);
Click the Solution Explorer tab.
FastTwainTutor.rc
file to open it, then double-click Dialog, and then double-click IDD_FASTTWAINTUTOR_DIALOG
Now, drag and drop 2 radio buttons, 1 check box, 1 button, 2 text boxes, and change their properties as follows:
Control | ID | Caption |
---|---|---|
Button1 | IDC_ACQUIRE | Fast Acquire |
Radio1 | IDC_NATIVE | Native |
Radio2 | IDC_MEMORY | Memory |
Check1 | IDC_USE_BUFFER_SIZE | Use Buffer Size |
Text1 | IDC_EDIT1 | IDC_BUFFERSIZE |
Text2 | IDC_EDIT2 | IDC_FILENAME |
Add the following member variables for the following controls. To do so, go to the Class View from Solution Explorer, select CFastTwainTutorDlg
, and then go to Project -> Add Variable menu, then do the following:
Control | ID | Member variable | Type |
---|---|---|---|
Check1 | IDC_USE_BUFFER_SIZE | m_bUseBufferSize | BOOL |
Text1 | IDC_BUFFERSIZE | m_nBufferSize | int |
Text2 | IDC_FILENAME | m_csFileName | CString |
From the View menu, select the Other Windows menu, then select the Resource View menu, then select Dialog, and select IDD_FASTTWAINTUTOR_DIALOG
.
Double-click the Fast Acquire button, and add the following code:
UpdateData();
L_INT nFormat;
L_UINT uTransferMode;
BOOL bMemory = IsDlgButtonChecked(IDC_MEMORY);
if (bMemory)
{
uTransferMode = LTWAIN_BUFFER_MODE;
nFormat = FILE_CCITT_GROUP4;
}
else
{
uTransferMode = LTWAIN_NATIVE_MODE;
nFormat = FILE_TIF;
}
L_INT nRet = m_MyTwain.FastAcquire((L_TCHAR *)(LPCTSTR)m_csFileName,
LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE,
uTransferMode,
nFormat,
1,
TRUE,
m_nBufferSize,
!m_bUseBufferSize);
if (nRet == 1)
AfxMessageBox(TEXT("Fast Scanning process done successfully..."));
else
{
CString csError;
csError.Format(TEXT("FastAcquire failed, Error = %d\n"), nRet);
AfxMessageBox(csError);
}
Compile and test the program.