Take the following steps to create and run a program that implement LEADTOOLS TWAIN features. Remember, the purpose of the TWAIN tutorial is to provide you a quick and easy way to generate a TWAIN program.
TwainAutoFeed
.TwainAutoFeed
project to expand it. Click the Header files, then Open TwainAutoFeed.h.Add the following line immediately before the class CTwainFeeder1App 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.
TwainAutoFeed
classes branch.CTwainAutoFeedApp
, and then double-click the CTwainAutoFeedApp(void)
constructor.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.
#include "StdAfx.h"
#if defined(WIN64)
#else
#pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLLVC10\\Win32\\Ltwvc_u.lib")
#endif // #if defined(WIN64)
Click the Solution Explorer tab.
Add the following class declaration before CTwainAutoFeedDlg class.
class LMyTwain : public LTwain
{
LEAD_DECLAREOBJECT(LMyTwain);
public:
LMyTwain();
virtual ~LMyTwain();
virtual L_INT BitmapCallBack(pBITMAPHANDLE pBitmap);
};
Click the Solution Explorer tab.
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 CTwainAutoFeedDlg 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 TwainAutoFeedDlg branch, and choose Properties.
OnDestroy
.Add the following code after the opening bracket {
:
m_MyTwain.EndSession();
LBase::UnloadLibraries(LT_ALL_LEADLIB);
Click the Solution Explorer tab.
TwainAutoFeed.rc
file to open it, then double-click Dialog, and then double-click IDD_TWAINAUTOFEED_DIALOG
.Now drag and drop 4 buttons, and change their properties as follows:
Control Type | ID | Caption |
---|---|---|
Button1 | IDC_ACQUIRE | Acquire |
Button2 | IDC_SET_AUTOFEED | Set Auto Feed |
Button3 | IDC_SET_FEEDER | Set Manual Feeder |
Button4 | IDC_SELECT_SOURCE | Select Source |
From the View menu, select the Other Windows menu, then select the Resource View menu, then select Dialog, and select IDD_TWAINAUTOFEED_DIALOG.
Double-click the Acquire button, and add the following code:
BITMAPHANDLE Bitmap;
m_MyTwain.Acquire(&Bitmap, sizeof(BITMAPHANDLE), LTWAIN_SHOW_USER_INTERFACE | LTWAIN_MODAL_USER_INTERFACE, NULL);
From the View menu, select the Other Windows menu, then select the Resource View menu, then select Dialog, and select IDD_TWAINAUTOFEED_DIALOG.
Double-click the Set Manual Feeder button, and add the following code:
m_MyTwain.SelectSource(NULL);
From the View menu, select the Other Windows menu, then select the Resource View menu, then select Dialog, and select IDD_TWAINAUTOFEED_DIALOG.
Double-click the Set Auto Feed button, and add the following code:
TW_CAPABILITY twCap;
L_INT nRet;
L_BOOL bEnable;
twCap.Cap = CAP_AUTOFEED;
twCap.ConType = TWON_ONEVALUE;
twCap.hContainer = GlobalAlloc(GHND, sizeof(TW_ONEVALUE));
pTW_ONEVALUE pOneValue = (pTW_ONEVALUE)GlobalLock(twCap.hContainer);
bEnable = TRUE;
pOneValue->ItemType = TWTY_BOOL;
pOneValue->Item = (TW_UINT32)bEnable;
GlobalUnlock(twCap.hContainer);
nRet = m_MyTwain.SetCapability(&twCap, LTWAIN_CAPABILITY_SET);
if (nRet == TWAIN_SUCCESS)
AfxMessageBox(TEXT("AutoFeed capability is enabled"));
else
AfxMessageBox(TEXT("Can't enable AutoFeed capability"));
From the View menu, select the Other Windows menu, then select the Resource View menu, then select Dialog, and select IDD_TWAINAUTOFEED_DIALOG<
Double-click the Select Source button, and add the following code:
TW_CAPABILITY twCap;
L_INT nRet;
L_BOOL bEnable;
twCap.Cap = CAP_FEEDERENABLED;
twCap.ConType = TWON_ONEVALUE;
twCap.hContainer = GlobalAlloc(GHND, sizeof(TW_ONEVALUE));
pTW_ONEVALUE pOneValue = (pTW_ONEVALUE)GlobalLock(twCap.hContainer);
bEnable = TRUE;
pOneValue->ItemType = TWTY_BOOL;
pOneValue->Item = (TW_UINT32)bEnable;
GlobalUnlock(twCap.hContainer);
nRet = m_MyTwain.SetCapability(&twCap, LTWAIN_CAPABILITY_SET);
if (nRet == TWAIN_SUCCESS)
{
AfxMessageBox(TEXT("CAP_FEEDERENABLED capability is enabled"));
m_MyTwain.FreeContainer(&twCap);
// check if there is document loaded in the feeder
twCap.Cap = CAP_FEEDERLOADED;
twCap.ConType = TWON_ONEVALUE;
twCap.hContainer = NULL;
nRet = m_MyTwain.GetCapability(&twCap, LTWAIN_CAPABILITY_GETCURRENT);
if (nRet == TWAIN_SUCCESS)
{
pOneValue = (pTW_ONEVALUE)GlobalLock(twCap.hContainer);
bEnable = pOneValue->Item;
if (bEnable)
AfxMessageBox(TEXT("There is document loaded in the feeder"));
else
AfxMessageBox(TEXT("There is no document loaded in the feeder"));
GlobalUnlock(twCap.hContainer);
m_MyTwain.FreeContainer(&twCap);
}
}
else
AfxMessageBox(TEXT("Can't enable Feeded capability"));
m_MyTwain.SelectSource(NULL);
Compile and test the program.