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.
TwainDuplex
.Click the Solution Explorer tab, and then click the TwainDuplex project to expand it. Click the Header files, then Open TwainDuplex.h.
8.Add the following line immediately before the class CTwainDuplexApp
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.
CTwainDuplexApp(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 the CTwainDuplexDlg
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.OnInitDialog()
function and add the following code after the 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);
OnDestroy
.Add the following code after the opening bracket {
:
m_MyTwain.EndSession();
LBase::UnloadLibraries(LT_ALL_LEADLIB);
Click the Solution Explorer tab.
TwainDuplex.rc
file to open it, then double-click Dialog, and then double-click IDD_TWAINDUPLEX_DIALOG
.Now drag and drop 2 buttons and 3 radio buttons, and change their properties as follows:
Control Type | ID | Caption |
---|---|---|
Button1 | IDC_ACQUIRE | Acquire |
From the View menu, select the Other Windows menu, then select the Resource View menu, then select Dialog, and select IDD_TWAINTUTOR3_DIALOG.
Double-click the Acquire button, and add the following code:
BITMAPHANDLE Bitmap;
L_INT nRet;
TW_CAPABILITY twCap;
m_MyTwain.SelectSource(NULL);
twCap.Cap = CAP_DUPLEX;
twCap.ConType = TWON_ONEVALUE;
twCap.hContainer = NULL;
nRet = m_MyTwain.GetCapability(&twCap, LTWAIN_CAPABILITY_GETVALUES);
if (nRet == TWAIN_SUCCESS)
{
// check if the selected driver supports duplex capability
pTW_ONEVALUE pOneValue = (pTW_ONEVALUE)GlobalLock(twCap.hContainer);
if (pOneValue->ItemType != TWTY_UINT16)
{
GlobalUnlock(twCap.hContainer);
m_MyTwain.FreeContainer(&twCap);
return;
}
TW_UINT16 item = (TW_UINT16)pOneValue->Item;
switch (item)
{
case TWDX_NONE:
AfxMessageBox(TEXT("Duplex capability is not supported in the selected driver"));
break;
case TWDX_1PASSDUPLEX:
AfxMessageBox(TEXT("1 Pass Duplex capability is supported in the selected driver"));
break;
case TWDX_2PASSDUPLEX:
AfxMessageBox(TEXT("2 Pass Duplex capability is supported in the selected driver"));
break;
}
GlobalUnlock(twCap.hContainer);
m_MyTwain.FreeContainer(&twCap);
// make sure the duplex capability is enabled
if (item != TWDX_NONE)
{
BOOL bEnable = TRUE;
twCap.Cap = CAP_DUPLEXENABLED;
twCap.ConType = TWON_ONEVALUE;
twCap.hContainer = GlobalAlloc(GHND, sizeof(TW_ONEVALUE));
pTW_ONEVALUE pOneValue = (pTW_ONEVALUE)GlobalLock(twCap.hContainer);
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("The duplex capability is enabled"));
else
AfxMessageBox(TEXT("Can't enable duplex capability"));
}
}
else
AfxMessageBox(TEXT("Duplex capability is not supported in the selected driver"));
// try to acquire pages using duplex capability
m_MyTwain.Acquire(&Bitmap, sizeof(BITMAPHANDLE), LTWAIN_SHOW_USER_INTERFACE | LTWAIN_MODAL_USER_INTERFACE, NULL);
Compile and test the program.