The LEADTOOLS WIA driver is available in LEADTOOLS version 16 or higher.
This tutorial shows a quick and easy way to generate a WIA program. For more in-depth WIA programming, refer to the WIA demo.
Take the following steps to create and run a program that implements LEADTOOLS WIA features.
C:\LEADTOOLS22\
, enter C:\LEADTOOLS22\Examples\Scanning\ClassLibrary
, then click OK. Then click Next.WiaAcquireTutor.h
.Add the following line immediately before the class CWiaAcquireTutorApp declaration (but keep in mind that you may have to change the path to where the header files reside):
#include "..\..\..\..\include\ClassLib\ltwrappr.h"
Click the Class View tab.
CWiaAcquireTutorApp(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.
Imports.cpp
.Imports.cpp
in the Solution Explorer and add the following lines:
#include "StdAfx.h"
#if defined(WIN64)
#pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltwvc_x.lib")
#else
#pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltwvc_u.lib")
#endif // #if defined(WIN64)
Click the Solution Explorer tab.
Add the following class declaration before CWiaAcquireTutorDlg
class:
class LMyWia : public LWia
{
LEAD_DECLAREOBJECT(LMyWia);
public:
LMyWia();
virtual ~LMyWia();
virtual L_INT AcquireCallBack(pBITMAPHANDLE pBitmap, L_TCHAR * pszFilename, L_UINT32 uPercent, L_UINT32 uFlags);
};
Click the Solution Explorer tab.
Add the following class:
LEAD_IMPLEMENTOBJECT(LMyWia);
LMyWia::LMyWia()
{
EnableCallBack(TRUE);
}
LMyWia::~LMyWia()
{
}
L_INT LMyWia::AcquireCallBack(pBITMAPHANDLE pBitmap, L_TCHAR * pszFilename, L_UINT32 uPercent, L_UINT32 uFlags)
{
//Copy the acquired bitmap here
return SUCCESS;
}
Click the Class View tab.
LMyWia
, and for Variable Declaration put m_MyWia
. Leave Access as Public and click OK.Click to open the CWiaAcquireTutorDlg branch. Double-click the OnInitDialog()
function and add the following code after line:
// TODO: Add extra initialization here
m_MyWia.InitSession(WiaVersion1);
Right-click the CWiaAcquireTutorDlg branch, and choose Properties.
Add the following code after the opening bracket {:
m_MyWia.EndSession();
LBase::UnloadLibraries(LT_ALL_LEADLIB);
Click the Solution Explorer tab.
WiaAcquireTutor.rc
file to open it, then double-click Dialog and then double-click IDD_WIAACQUIRETUTOR_DIALOG
.Now, drag and drop 2 buttons, and change their properties as follows:
Control | ID | Caption |
---|---|---|
Button1 | IDC_SELECT_SRC |
Select Source |
Button2 | IDC_ACQUIRE |
Acquire |
From the View menu, select the Other Windows menu, then select the Resource View menu, then select Dialog, and select IDD_WIAACQUIRETUTOR_DIALOG
.
Double-click the Select Source button, and add the following code:
m_MyWia.SelectDeviceDlg(WiaDeviceTypeDefault, L_WIA_SELECT_DEVICE_NODEFAULT);
From the View menu, select the Other Windows menu, then select the Resource View menu, then select Dialog, and select IDD_WIAACQUIRETUTOR_DIALOG
.
Double-click the Acquire button, and add the following code:
m_MyWia.m_MyWia.Acquire(L_WIA_SHOW_USER_INTERFACE | L_WIA_DEVICE_DIALOG_USE_COMMON_UI, NULL, NULL, NULL, NULL);
Compile and test the program.