1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
Option Explicit
Const MESSAGECODE = -2147120754 ' Message Code
Dim lErrorCode ' As long
Dim sErrorDescription ' As String
Dim bDebug ' As Boolean
Dim iRetour ' As long
Dim s_cheminsauv 'As string
Dim i 'As long
Dim oRst ' As ADODB.Recordset
Dim sRequete
Dim DX ' As string
Dim path ' as string
dim hwnd ' as string
dim a,b,c,d,e
' Initialisation'
lErrorCode = 0
' mGlob.Error.Clear
sErrorDescription = "0"
bDebug = true
if bDebug then
msgbox "SCRIPT Scanner"
msgbox "BatchID " & CSTR(mdata.batchid)
msgbox "WorkOrder " & CSTR(mData.ManCode)
end if
Set DX = CreateObject("DynamicWrapperX")
DX.Register "user32", "GetActiveWindow", "r = l"
hwnd = DX.GetActiveWindow()
'msgbox hwnd
DX.Register "EZTW32", "TWAIN_OpenSourceManager", "i=l","r=l"
DX.Register "EZTW32", "TWAIN_CloseSource", "r=l"
DX.Register "EZTW32", "TWAIN_LoadSourceManager", "r=l"
DX.Register "EZTW32", "TWAIN_OpenDefaultSource", "i=l", "r=l"
DX.Register "EZTW32","TWAIN_SelectImageSource", "i=l", "r=l"
DX.Register "EZTW32","TWAIN_AcquireToClipboard","i=ll", "r =l"
DX.Register "EZTW32","TWAIN_State", "r=l"
DX.Register "EZTW32","TWAIN_SetCurrentUnits","i=l","r=l"
DX.Register "EZTW32","TWAIN_SetCurrentResolution","i=d","r=l"
DX.Register "EZTW32","TWAIN_SetCurrentPixelType","i=l","r=l"
DX.Register "EZTW32","TWAIN_SetBitDepth","i=l","r=l"
DX.Register "EZTW32","TWAIN_SetHideUI","i=l","r=l"
'***************'
DX.Register "EZTW32","TWAIN_GetCurrentUnits","r=l"
DX.Register "EZTW32","TWAIN_GetCurrentResolution","r=d"
DX.Register "EZTW32","TWAIN_GetPixelType","r= l"
DX.Register "EZTW32","TWAIN_GetBitDepth","r=l"
DX.Register "EZTW32","TWAIN_GetHideUI","r=l"
Set oRst = CreateObject("ADODB.Recordset")
sRequete = "select MDATA_VALUE from XTAB_MASTERDATA where UNIT_REF = 99 and MDATA_CODE = 'SCAN_PATH'"
'Construction de la requete complete
Set oRst = mglob.DB.Condata.execute (sRequete)
path= oRst.Fields("MDATA_VALUE").value
'msgbox path
if isnull(path) or path = "" then ErrorRaise "La valeur du master data " & "SCAN_PATH" & " est vide"
DX.TWAIN_CloseSource()
DX.TWAIN_LoadSourceManager()
DX.TWAIN_OpenSourceManager(hwnd)
iRetour = DX.TWAIN_OpenDefaultSource(hwnd)
'msgbox iRetour
If iRetour = 0 Then
iRetour = DX.TWAIN_SelectImageSource(hwnd)
If iRetour = 1 Then
iRetour = DX.TWAIN_OpenDefaultSource(hwnd)
' msgbox iRetour
End If
End If
If iRetour = 0 Then
msgbox "error"
End If
'mdata.InsertData outsImageDirectory,0,path
If DX.TWAIN_State() < 4 Then
MsgBox("Impossible de paramÿtrer le scanner")
' close()
Else
'parametres du scanner
DX.TWAIN_SetCurrentUnits(0) 'DPI
DX.TWAIN_SetCurrentResolution(72) 'en points par pouces
DX.TWAIN_SetCurrentPixelType(2) ' Scan format 0 = B&W, 1 Grey, 2 RGB
DX.TWAIN_SetBitDepth(8) ' Bit Depth 1, 2, 4, 8 but depends on Pixeltype
DX.TWAIN_SetHideUI(1)
' a = DX.TWAIN_GetCurrentUnits() 'DPI
' msgbox a
' b = DX.TWAIN_GetCurrentResolution() 'en points par pouces
' msgbox b
' c = DX.TWAIN_GetPixelType() ' Scan format 0 = B&W, 1 Grey, 2 RGB
' msgbox c
' d = DX.TWAIN_GetBitDepth() ' Bit Depth 1, 2, 4, 8 but depends on Pixeltype
' msgbox d
' e = DX.TWAIN_GetHideUI()
' msgbox e
End If
'scan du document
msgbox "coucou"
iRetour = DX.TWAIN_AcquireToClipboard(hwnd, 32)
msgbox iRetour
If iRetour = 0 Then
MsgBox("Le scan du document a échoué.")
' close()
End If
DX.TWAIN_CloseSource()
s_cheminsauv = "c:\toto.jpg"
i=1 |
Partager