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.
1. |
Start Microsoft Visual Studio. |
2. |
Select the File->New menu option, click the "Project" menu. |
3. |
From "Project Types" select "Other Languages" to expand it, then select "Visual C++" to expand it, then select "MFC". From the right window select "MFC Application". |
4. |
In the Project Name dialog box, enter "TwainAutoFeed". |
5. |
In the Location dialog box, use the "Examples\ClassLibrary\MSVC" directory of your LEAD installation. For example, if you installed LEADTOOLS in "C:\LEADTOOLS 19\", enter "C:\LEADTOOLS 19\Examples\ClassLibrary\MSVC", then Click OK. Then click "Next". |
6. |
Choose "Dialog based" and click "Finish". |
7. |
Click on the "Solution Explorer" tab, and then click on the "TwainAutoFeed" project to expand it. Click on the Header files, then Open "TwainAutoFeed.h". |
8. |
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"
9. |
Click on the "Class View" tab. |
10. |
Click to open the "TwainAutoFeed" classes branch. |
11. |
Click "CTwainAutoFeedApp", and then double click the CTwainAutoFeedApp(void) constructor. |
12. |
Add the following lines after |
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);
13. | Create a new file called Imports.cpp in place it beside your project files. | |
a. | In the Project Workspace, click the Solution Explorer tab. | |
b. | Double-click the TwainAutoFeed folder to open it. | |
c. | Right-click the Source files folder and select Add New item. | |
d. | Expand Visual C++ tree, if it is not already expanded. | |
e. | Select Code from the sub tree. | |
f. | Select C++ File (.cpp) from the right window. | |
g. | In the name text box, specify Imports.cpp | |
h. | Click the Add button. | |
i. | Double-click the 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)
14. |
Click on the "Solution Explorer" tab. |
15. |
Double-click the "TwainAutoFeed" folder to open it. |
16. |
Double-click the "Header Files" folder to open it. Then double click " TwainAutoFeedDlg.h" file to open it. |
17. |
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);
};
18. |
Click on the "Solution Explorer" tab. |
19. |
Double-click the "TwainAutoFeed" folder to open it. |
20. |
Double-click the "Source Files" folder to open it. Then double click "TwainAutoFeedDlg.cpp" file to open it. |
21. |
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;
}
22. |
Click on the "Class View" tab. |
23. |
Right click "CTwainAutoFeedDlg" and select Add "Add Variable..." |
24. |
For Variable Type enter LMyTwain, and for Variable Declaration put m_MyTwain. Leave Access as "Public" and click OK. |
25. |
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);
26. |
Right click the TwainAutoFeedDlg branch, and choose "Properties". |
27. |
From the "Properties" window toolbar, click on the Messages icon. |
|
Then click on the empty area beside the item "WM_DESTROY" and choose OnDestroy. |
28. |
Add the following code after the opening bracket {: |
m_MyTwain.EndSession();
LBase::UnloadLibraries(LT_ALL_LEADLIB);
29. | Click on the "Solution Explorer" tab. | |
30. | Double-click the "TwainAutoFeed" folder to open it. | |
31. | Double-click the "Resource Files" folder to open it. Then double click " TwainAutoFeed.rc" file to open it, then double click "Dialog", and then double click "IDD_TWAINAUTOFEED_DIALOG" | |
32. | Now, drag and drop 1 button, and change their properties as follows: | |
ID | Caption | |
IDC_ACQUIRE | Acquire | |
IDC_SET_AUTOFEED | Set Auto Feed | |
IDC_SET_FEEDER | Set Manual Feeder | |
IDC_SELECT_SOURCE | Select Source | |
33. | From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_TWAINAUTOFEED_DIALOG" | |
34. | Double click on "Acquire" button, and add the following code: |
BITMAPHANDLE Bitmap;
m_MyTwain.Acquire(&Bitmap, sizeof(BITMAPHANDLE), LTWAIN_SHOW_USER_INTERFACE | LTWAIN_MODAL_USER_INTERFACE, NULL);
35. |
From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_TWAINAUTOFEED_DIALOG" |
36. |
Double click on "Set Manual Feeder" button, and add the following code: |
m_MyTwain.SelectSource(NULL);
37. |
From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_TWAINAUTOFEED_DIALOG" |
38. |
Double click on "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"));
39. |
From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_TWAINAUTOFEED_DIALOG" |
40. |
Double click on "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);
41. |
Compile and test the program. |