Get a Fast Twain Scan from a Scanner
Take the following steps to get fast twain scan using the LEADTOOLS Fast TWAIN features:
1. |
Create a new directory in the LTWINxxx\EXAMPLES\DLL directory called EZTWN2. |
2. |
Copy everything in the EZFUNC directory into the EZTWN2 directory. |
3. |
Rename the EZFunc.c file to be EZFunc.cpp. |
4. |
Remove the EXFunc.cpp from the project and add the EZFunc.cpp in its place. |
5. |
Compile the project as it is and run EZFUNC32.exe to familiarize yourself with the basic program. You can run the exe file from the MS-DOS prompt, or set the image file to load through the Project->Settings->Debug->Program Arguments menu. |
6. |
On the Insert menu, select Files into Project. Add the lttw2_n.lib file to the project from the LTWINxxx\LIB directory. |
7. |
Define the following global variables in EZFUNC.CPP in the EZTWN directory: |
HTWAINSESSION hSession = NULL;
FASTCONFIG BestConfig;
8. |
In the project workspace go to the resources tab. Add a menu ("MAIN_MENU") to the application with the following menu items: |
|
|
ID |
Caption |
|
IDM_SELECT_SOURCE |
Select Source |
|
IDM_FIND_FAST_CONFIG |
Find Fast Config |
|
IDM_ACQUIRE_FAST_CONFIG |
Acquire Fast Config |
9. |
In the InitApplication function change the line: |
wcWindowClass.lpszMenuName = NULL; /* No menu */
to be
wcWindowClass.lpszMenuName = TEXT("MAIN_MENU");
10. |
In the EZFunc.cpp add the following includes: |
#include "resource.h"
#include "LTWINxxx\Include\ltTw2.h"
11. |
In the MainWndProc function and before the handling of the WM_PALETTECHANGED message add the following code: |
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDM_SELECT_SOURCE:
{
}
break;
case IDM_FIND_FAST_CONFIG:
{
}
break;
case IDM_ACQUIRE_FAST_CONFIG:
{
}
break;
}
}
break;
12. |
In the WM_CREATE message handler add the following code at the end of it (after SendMessage (hWnd, WM_QUERYNEWPALETTE, 0, 0L);): |
APPLICATIONDATA AppData;
AppData.uStructSize = sizeof(APPLICATIONDATA);
AppData.hWnd = hWnd;
lstrcpy (AppData.szManufacturerName, TEXT("LEAD Technologies, Inc."));
lstrcpy (AppData.szAppProductFamily, TEXT("LEAD Test Applications"));
lstrcpy (AppData.szVersionInfo, TEXT("Version 1.0"));
lstrcpy (AppData.szAppName, TEXT("TWAIN Test Application"));
nRet = L_TwainInitSession(&hSession, &AppData);
if (nRet != SUCCESS)
return FALSE;
/* Unlock Document support.
Note that this is a sample key, which will not work in your toolkit. */ L_UnlockSupport(L_SUPPORT_DOCUMENT, TEXT("TestKey"));
13. |
In the WM_DESTROY message handler add the following code at the end of it (before the PostQuitMessage (0);): |
L_TwainEndSession(&hSession);
14. |
In the IDM_SELECT_SOURCE menu handler add the following code: |
case IDM_SELECT_SOURCE:
{
nRet = L_TwainSelectSource(hSession, NULL);
}
break;
15. |
In the IDM_FIND_FAST_CONFIG menu handler add the following code: |
case IDM_FIND_FAST_CONFIG:
{
pFASTCONFIG pTestConfigs = NULL;
L_INT nTestConfigsCount = 0;
nRet = L_TwainFindFastConfig(hSession,
TEXT("c:\\temp"),
LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE,
8, 5, NULL, 0,
&pTestConfigs,
&nTestConfigsCount,
&BestConfig,
sizeof(FASTCONFIG),
NULL,
NULL);
if (nRet == SUCCESS)
MessageBox(hWnd, TEXT("Find Fast Configuration process completed"), TEXT("Fast Config"), MB_OK);
else
MessageBox(hWnd, TEXT("An error occurred during the Finding Fast Configuration process."), TEXT("Fast Config"), MB_OK);
}
break;
16. |
In the IDM_ACQUIRE_FAST_CONFIG menu handler add the following code: |
case ID case IDM_ACQUIRE_FAST_CONFIG:
{
nRet = L_TwainAcquireMulti(hSession,
TEXT("c:\\temp\\testconfig.tif"),
LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE,
BestConfig.uTransferMode,
BestConfig.nFileFormat,
BestConfig.nBitsPerPixel,
TRUE,
BestConfig.ulBufferSize,
TRUE,
NULL,
NULL);
if (nRet == SUCCESS)
MessageBox(hWnd, TEXT("Image acquisition using the Fast TWAIN Configuration is completed."), TEXT("Fast Config"), MB_OK);
else
MessageBox(hWnd, TEXT("An error occurred while acquiring images using the Fast TWAIN Configuration."), TEXT("Fast Config"), MB_OK);
}
break;
17. |
Add the following definition in the top of the EZFunc.cpp file, and before any include statement: |
#define USE_NEWTWAIN
18. |
Compile and test the program. |