✎ NOTE
The purpose of this WIA tutorial is to provide you a quick and easy way to acquire images from a WIA source. For more in-depth WIA programming, refer to the WIA demo.
To acquire images from a WIA source:
Create a new directory in the \Examples\CDLL directory called WiaTutorial.
Copy everything in the SimpleLoad directory into the WiaTutorial directory.
Compile the project as it is and run SimpleLoad.exe to familiarize yourself with the basic program.
In the Imports.cpp, add the following lines:
#if defined(WIN64)
#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\x64\\Ltwia_x.lib")
#else
#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Ltwia_u.lib")
#endif // #if defined(WIN64)
Add the following line in StdAfx.h in the WiaTutorial directory:
#include "..\\..\\..\\include\\ltwia.h"
Define the following global variable in Ezfunc.h in the WiaTutorial directory:
HWIASESSION hSession = NULL;
Also, add the following defines:
#define IDM_SELECT_SOURCE 200
#define IDM_ACQUIRE 201
Edit EZFUNC.RC file in the WiaTutorial directory and add the following lines:
#include "EZFUNC.H"
MAIN_MENU MENU
BEGIN
MENUITEM "Select Source" IDM_SELECT_SOURCE
MENUITEM "Acquire" IDM_ACQUIRE
END
In the InitApplication function change the line:
wcWindowClass.lpszMenuName = NULL; /* No menu */
to be
wcWindowClass.lpszMenuName = TEXT("MAIN_MENU");
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_ACQUIRE:
{
}
break;
}
}
break;
In the WM_CREATE message handler add the following code at the end of it (after SendMessage(hWnd, WM_QUERYNEWPALETTE, 0, 0L);
):
nRet = L_WiaInitSession(WiaVersion1, &hSession);
if (nRet != WIA_SUCCESS)
return FALSE;
In the WM_DESTROY message handler add the following code at the end of it (before the PostQuitMessage(0);
):
L_WiaEndSession(hSession);
In the IDM_SELECT_SOURCE menu handler add the following code:
case IDM_SELECT_SOURCE:
{
nRet = L_WiaSelectDeviceDlg(hSession, hWnd, WiaDeviceTypeDefault, L_WIA_SELECT_DEVICE_NODEFAULT);
}
break;
In the IDM_ACQUIRE menu handler add the following code:
case IDM_ACQUIRE:
{
nRet = L_WiaAcquire(hSession, hWnd, L_WIA_SHOW_USER_INTERFACE|L_WIA_DEVICE_DIALOG_USE_COMMON_UI, NULL, NULL, NULL, NULL, WiaAcquireCB, NULL);
if (nRet != WIA_SUCCESS)
return nRet;
InvalidateRect (hWnd, NULL, FALSE);
}
break;
In Ezfunc.cpp file, add the following function before MainWndProc function:
L_INT CALLBACK WiaAcquireCB(HWIASESSION hSession, pBITMAPHANDLE pBitmap, L_TCHAR * pszFilename, L_UINT32 uPercent, L_UINT32 uFlags, L_VOID * pUserData)
{
UNREFERENCED_PARAMETER(hSession);
UNREFERENCED_PARAMETER(pUserData);
UNREFERENCED_PARAMETER(pszFilename);
UNREFERENCED_PARAMETER(uPercent);
UNREFERENCED_PARAMETER(uFlags);
if(pBitmap)
{
if(pBitmap->Flags.Allocated)
{
if (LeadBitmap.Flags.Allocated)
L_FreeBitmap(&LeadBitmap);
L_CopyBitmap(&LeadBitmap, pBitmap, sizeof(BITMAPHANDLE));
L_FreeBitmap(pBitmap);
pBitmap = NULL;
}
}
return WIA_SUCCESS;
}
Compile and test the program.