Available in the LEADTOOLS Imaging toolkit. |
Twain Feeder: Tutorial #2 (Visual Basic)
Take the following steps to start a project and to add some code that acquires the images using Fast Twain:
1. |
Start Visual Basic. |
2. |
Add the LEAD RasterTwain Object Library and LEAD Raster Variant Object Library to your project. |
|
On the Project pull-down menu, use the References option, and select the LEAD RasterTwain Object Library. |
|
On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library. |
3. |
Add the following code to the general declarations section of your project: |
Public TwainCap As New LEADTwainCapability_U
Public WithEvents RasterTwain As LEADRasterTwain_U
4. |
Add the following code to the main form's Load procedure: |
Set RasterTwain = New LEADRasterTwain_U
RasterTwain.InitSession hWnd
RasterTwain.EnableMethodErrors = False
5. |
Add the following code to the main form's Unload procedure: |
RasterTwain.EndSession
6. |
Add the following button: |
||
|
Name |
Caption |
|
|
cmdAcquire |
Acquire |
|
7. |
Code the Acquire control's Click procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
Private Sub cmdAcquire_Click()
Dim nRet As Integer
Dim bEnable As Boolean
RasterTwain.SelectSource
TwainCap.CapInfo.Capability = L_CAP_FEEDERENABLED
TwainCap.CapInfo.ConType = L_TWON_ONEVALUE
bEnable = True
Dim RasVar As New LEADRasterVariant_U
RasVar. = VALUE_BOOLEAN
RasVar.
= bEnable
TwainCap.CapOneValue.OneValItemType = L_TWTY_BOOL
TwainCap.CapOneValue.OneValCapValue = RasVar
nRet = RasterTwain.SetCapability2(TwainCap, L_LTWAIN_CAPABILITY_SET)
If nRet = 0 Then
MsgBox "CAP_FEEDERENABLED capability is enabled"
' check if there is document loaded in the feeder
TwainCap.CapInfo.Capability = L_CAP_DUPLEX
TwainCap.CapInfo.ConType = L_TWON_ONEVALUE
nRet = RasterTwain.GetCapability2 (TwainCap, L_LTWAIN_CAPABILITY_GETVALUES)
If nRet = 0 Then
' check if the selected driver supports duplex capability
bEnable = TwainCap.CapOneValue.OneValCapValue.BooleanValue
If bEnable Then
MsgBox "There is document loaded in the feeder"
Else
MsgBox "There is no document loaded in the feeder"
End If
End If
Else
MsgBox "Can't enable AutoFeed capability"
End If
' try to acquire pages using CAP_FEEDERENABLED and CAP_FEEDERLOADED capabilities
RasterTwain.Acquire L_LTWAIN_SHOW_USER_INTERFACE Or L_LTWAIN_MODAL_USER_INTERFACE
End Sub