Available in the LEADTOOLS Imaging toolkit. |
Twain Duplex (Visual C++ 5.0)
Take the following steps to start a project:
1. |
Start a new project as follows: |
|
|
Run Microsoft Visual C++ 5.0, select the File >New menu option, and do the following: |
|
|
a. |
Click the Projects tab. |
|
b. |
Select MFC AppWizard (exe) as the project type. |
|
c. |
In the Project name text box, specify tutor. |
|
d. |
In the Location text box, specify the path of the project. |
|
e. |
Click the OK button. |
2. |
In the Step 1 dialog box, do the following: |
|
|
a. |
Select Dialog based. |
|
b. |
Click the Next button. |
3. |
In the Step 2 of 4 dialog box, do the following: |
|
|
a. |
Ensure that About Box is selected. |
|
b. |
Ensure that 3D Controls is selected. |
|
c. |
Select ActiveX Controls. |
|
d. |
Click the Next button. |
4. |
In the Step 3 of 4 dialog box, do the following: |
|
|
a. |
For comments, ensure that Yes, Please is selected. |
|
b. |
For how to use the MFC library, select Use MFC in a Shared DLL. |
|
c. |
Click the Next button. |
5. |
In the Step 4 of 4 dialog box, just click Finish. |
|
6. |
Read the New Project Information, and click OK. (The AppWizard creates the project files and opens the project.) |
|
7. |
Add #import and #include statements to your program so you can access the LEAD COM constants and classes: |
|
|
a. |
In the Project Workspace, click the FileView tab. |
|
b. |
Double-click the tutor files folder to open it. |
|
c. |
Double-click the Header Files folder to open it. |
|
d. |
Double-click the StdAfx.h file to edit it. |
8. |
Add the following lines to the end of the file (keep in mind, you may have to change the path to where the dll's reside). If you used the defaults, it should be "C:\Program Files\LEAD Technologies\LEADTOOLS Imaging 16\Bin\CDLL\Win32". |
#import "LtocxVariantu.dll" no_namespace, named_guids
#import "LtocxTwainu.dll" no_namespace, named_guids
9. |
Add an ILEADRasterTwain_U pointer to the class and set it to NULL in the constructor. |
|
|
a. |
In the Project Workspace, click the Class View tab. |
|
b. |
Select the CTutorDlg class. |
|
c. |
Right-click and choose "Add Member Variable". |
|
d. |
For Variable Type enter ILEADRasterTwain_U. |
|
e. |
For Variable Declaration enter *m_pRasterTwain. |
|
f. |
Leave Access as Public. |
|
g. |
Click the OK button. |
|
h. |
In the Class View tab, double-click the CTutorDlg constructor function. |
|
i. |
Add the following line to the end of the constructor: |
m_pRasterTwain = NULL;
10. |
Go to the Project WorkSpace and click the Resource View tab. Double-click Dialog and double-click IDD_TUTOR_DIALOG to bring up the application's dialog box. |
|
11. |
Add the following button: |
|
|
ID |
Caption |
|
IDC_ACQUIRE |
Acquire |
12. |
Add the following code to the end of OnInitDialog before the return statement: |
CoInitialize(NULL);
if (m_pRasterTwain == NULL)
{
CoCreateInstance(CLSID_LEADRasterTwain_U, NULL, CLSCTX_ALL, IID_ILEADRasterTwain_U, (void**)&m_pRasterTwain);
}
if (m_pRasterTwain == NULL)
return FALSE;
m_pRasterTwain->InitSession ((long)GetSafeHwnd());
m_pRasterTwain->put_EnableMethodErrors (TRUE);
13. |
To end the Twain session and free memory allocated by the COM object, add the following code in the destructor of the CTutorDlg. To do so, press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
In the Class name combo box, select CTutorDlg. |
|
b. |
In the Object IDs list box, select CTutorDlg. |
|
c. |
In the Messages list box, select WM_DESTROY. |
|
d. |
Click the Add Function button. Choose OK for the default function name (OnDestroy). |
|
e. |
Click the Edit Code button to enter the following code before CDialog::OnDestroy(). |
if (m_pRasterTwain)
{
m_pRasterTwain->EndSession();
}
CoUninitialize();
14. |
Add code for the select source button (IDC_ACQUIRE). To do so, press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CTutorDlg. |
|
c. |
In the Object IDs list box, select IDC_ACQUIRE. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add Function button. Choose OK for the default function name (OnAcquire). |
|
f. |
Click the Edit Code button to start entering the code. |
void CTutorDlg::OnAcquire()
{
int nRet = 0;
ILEADTwainCapability_U *pTwainCap;
m_pRasterTwain->SelectSource();
CoCreateInstance(CLSID_LEADTwainCapability_U, NULL, CLSCTX_ALL, IID_ILEADTwainCapability_U, (void**)&pTwainCap);
pTwainCap->CapInfo->Capability = L_CAP_DUPLEX;
pTwainCap->CapInfo->ConType = L_TWON_ONEVALUE;
nRet = m_pRasterTwain->GetCapability2 (pTwainCap, L_LTWAIN_CAPABILITY_GETVALUES);
if (nRet == 0)
{
// check if the selected driver supports duplex capability
if (pTwainCap->CapOneValue->OneValItemType != L_TWTY_UINT16)
{
m_pRasterTwain->EndSession();
return;
}
int item = pTwainCap->CapOneValue->OneValCapValue->LongValue;
switch (item)
{
case L_TWDX_NONE:
AfxMessageBox(TEXT("Duplex capability is not supported in the selected driver"));
break;
case L_TWDX_1PASSDUPLEX:
AfxMessageBox(TEXT("1 Pass Duplex capability is supported in the selected driver"));
break;
case L_TWDX_2PASSDUPLEX:
AfxMessageBox(TEXT("2 Pass Duplex capability is supported in the selected driver"));
break;
}
// make sure the duplex capability is enabled
if (item != L_TWDX_NONE)
{
BOOL bEnable = TRUE;
pTwainCap->CapInfo->Capability = L_CAP_DUPLEXENABLED;
pTwainCap->CapInfo->ConType = L_TWON_ONEVALUE;
ILEADRasterVariant_U * pRasVar = NULL;
CoCreateInstance(CLSID_LEADRasterVariant_U, NULL, CLSCTX_ALL, IID_ILEADRasterVariant_U, (void**)&pRasVar);
pRasVar->= VALUE_BOOLEAN;
pRasVar-> = bEnable;
pTwainCap->CapOneValue->OneValItemType = L_TWTY_BOOL;
pTwainCap->CapOneValue->OneValCapValue = pRasVar;
nRet = m_pRasterTwain->SetCapability2(pTwainCap, L_LTWAIN_CAPABILITY_SET);
if (nRet == 0)
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_pRasterTwain->Acquire(L_LTWAIN_SHOW_USER_INTERFACE || L_LTWAIN_MODAL_USER_INTERFACE);
}
15. |
Compile and test the program. |