Page 1 of 1

Posted: Mon May 06, 2002 7:47 pm
by BackupUser
Restored from previous forum. Originally posted by marlo.

Hi all, i think we, beginners and not so beginners can need this to be translated fron VB to PB, is for use of TWAIN DEVICES. Here, the VB code:

'The TWAIN32d.dll should be in the System directory
Private Declare Function TWAIN_AcquireToFilename Lib "TWAIN32d.DLL" (ByVal hwndApp As Long, ByVal bmpFileName As String) As Integer
Private Declare Function TWAIN_IsAvailable Lib "TWAIN32d.DLL" () As Long
Private Declare Function TWAIN_SelectImageSource Lib "TWAIN32d.DLL" (ByVal hwndApp As Long) As Long
Dim ScrollAreaScan As CScrollArea

Private Sub cmdScan_Click()
Dim Ret As Long, PictureFile As String
PictureFile = App.Path & "\temp.bmp"
'PicturFile is the temporary file "temp.bmp"
'In "temp.bmp" the image will stored until the end of the action
Ret = TWAIN_AcquireToFilename(Me.hwnd, PictureFile)
If Ret = 0 Then
'If the scan is successful
picScan.Picture = LoadPicture(PictureFile)
'Load the temporary picture file
ScrollAreaScan.ReSizeArea
'Resize the picture control
Kill PictureFile
'Delete the temporary picture file
Else
MsgBox "Scan not successful!", vbCritical, "Scanning"
End If
End Sub

Private Sub cmdSelect_Click()
TWAIN_SelectImageSource (Me.hwnd)
End Sub

Private Sub Form_Load()
Set ScrollAreaScan = New CScrollArea
Set ScrollAreaScan.VBar = VScroll
Set ScrollAreaScan.HBar = HScroll
Set ScrollAreaScan.InnerPicture = picScan
Set ScrollAreaScan.FramePicture = Picture1
End Sub



from the ass of the world

Posted: Mon May 06, 2002 7:52 pm
by BackupUser
Restored from previous forum. Originally posted by marlo.

I forget the link to above code:
http://www.planetsourcecode.com/vb/scri ... 3&lngWId=1


Thanks


from the ass of the world

Posted: Tue May 07, 2002 5:57 pm
by BackupUser
Restored from previous forum. Originally posted by marlo.

Here is the code converted with superb Vis2Pure of main form to make a SCANNER program.
If any can help me with the code to send functions to TWAIN32d.dll
This is the PB form code:

WinW=767 ; Window width.
WinH=476 ; Window height.
WinX=(GetSystemMetrics_(#SM_CXSCREEN)-WinW)/2 ; Window centered horizontally.
WinY=(GetSystemMetrics_(#SM_CYSCREEN)-WinH)/2 ; Window centered vertically.

; See if memory to create everything is available, and abort program if not.

frmMain_hWnd=OpenWindow(0,WinX,WinY,WinW,WinH,#PB_Window_SystemMenu|#WS_MAXIMIZE,"Scan")
If frmMain_hWnd=0 Or CreateGadgetList(frmMain_hWnd)=0
End
EndIf

; Memory for everything is available, so now create all items on the window.

;-CreateItems.

#cmdSelect=1
cmdSelect_hWnd=ButtonGadget(#cmdSelect,8,8,368,40,"Select TWAIN Source")

#cmdScan=2
cmdScan_hWnd=ButtonGadget(#cmdScan,384,8,368,40,"Scan!")

#Picture1=3
Picture1_ID=LoadImage(#Picture1,"C:\") ; !NEED PICTURE PATH.
Picture1_hWnd=ImageGadget(#Picture1,0,376,736,16,Picture1_ID)

#picScan=4
picScan_ID=LoadImage(#picScan,"C:\") ; !NEED PICTURE PATH.
picScan_hWnd=ImageGadget(#picScan,0,0,112,80,picScan_ID)

;===========================================================================
;-STARTUP CODE.
; Put variable declarations, procedures, and other initialization code here.
;===========================================================================

;ActivateGadget(#ID) ; Gadget with initial focus.

;===========================================================================
;-MAIN PROGRAM LOOP.
; Wait for user/system to do something and then take the appropriate action.
;===========================================================================

Repeat
EventID=WaitWindowEvent()
Select EventID
Case #PB_EventGadget
Select EventGadgetID()
Case #cmdSelect : Gosub cmdSelect_Click
Case #cmdScan : Gosub cmdScan_Click
EndSelect
EndSelect
Until EventID=#PB_EventCloseWindow

;===========================================================================
;-SHUTDOWN CODE.
; Put your end-of-program routine here, or leave solely as "End" if desired.
;===========================================================================

End

;===========================================================================
;-SUBROUTINES.
; Put your own subroutines here.
;===========================================================================



;===========================================================================
;-ITEM CLICKS.
; Put your item click routines here.
;===========================================================================

;===========================================================================
;- cmdSelect_Click
cmdSelect_Click:

Return

;===========================================================================
;- cmdScan_Click
cmdScan_Click:

Return

; **************************************************************************
; * END OF CONVERTED FORM *


The twain32d.dll only have 3 functions,as I see:

TWAIN_AcquireToFilename
TWAIN_IsAvailable
TWAIN_SelectImageSource

as you can see on the previuos message, in VB code.
Thanks for any help.

from the ass of the world

Posted: Tue May 07, 2002 6:47 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

I just took a quick look here and that DLL does not exist on my machine. Usually the Twain DLL comes with the device that needs it.

My scanner uses a DLL called TWAIN_32.DLL and it does not contain the calls you specify.

Posted: Tue May 07, 2002 7:47 pm
by BackupUser
Restored from previous forum. Originally posted by marlo.

hi Paul. In the link on the message in this topic you can download the archive is about 65k called twain32d.dll.
Can be included the file when compiled?



from the ass of the world

Posted: Tue May 07, 2002 9:16 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

Sorry marlo... missed the DLL link.
Anyway, here is a translation of your code (with a few additions) :)

Code: Select all

If OpenLibrary(0,"Twain32d.dll")
  IsAvailable=IsFunction(0,"TWAIN_IsAvailable")
  SelectImageSorce=IsFunction(0,"TWAIN_SelectImageSource")
  AcquireToFilename=IsFunction(0,"TWAIN_AcquireToFilename")
  Else
  MessageRequester("Error","Could Not Open DLL",#MB_ICONERROR)
EndIf
 
 
picpath.s="C:\pic.bmp"
#cmdSelect=1
#cmdScan=2
#cmdView=3
#img=4
 
hWnd=OpenWindow(0,(GetSystemMetrics_(#SM_CXSCREEN)-767)/2,(GetSystemMetrics_(#SM_CYSCREEN)-476)/2,767,476,#PB_Window_SystemMenu,"Scan")
If hWnd=0 Or CreateGadgetList(hWnd)=0:End:EndIf
ButtonGadget(#cmdSelect,10,10,190,30,"Select TWAIN Source")
ButtonGadget(#cmdScan,210,10,190,30,"Scan!")
ButtonGadget(#cmdView,410,10,190,30,"View Saved")
 
 
Repeat
  EventID=WaitWindowEvent()
  Select EventID
    Case #PB_EventGadget
    Select EventGadgetID()
    
      Case #cmdSelect
      Gosub cmdSelect_Click
       
      Case #cmdScan
      Gosub cmdScan_Click
      Gosub cmdView
 
      Case #cmdView
      Gosub cmdView
       
    EndSelect
  EndSelect
Until EventID=#PB_EventCloseWindow
End
 
 
cmdSelect_Click:
  result=CallFunctionFast(SelectImageSorce,hWnd)
Return
 
cmdScan_Click:
  result=CallFunctionFast(AcquireToFilename,hWnd,picpath)
Return
 
cmdView:
  hImage=LoadImage(#img,picpath)
  If hImage
    StartDrawing(WindowOutput())
    DrawImage(hImage,10,50,ImageWidth(),ImageHeight())
    StopDrawing()
  EndIf 
Return

Posted: Fri May 10, 2002 9:42 am
by BackupUser
Restored from previous forum. Originally posted by marlo.

Thanks Paul!!!! WORKS OK!!

from the ass of the world

Posted: Fri May 10, 2002 9:44 am
by BackupUser
Restored from previous forum. Originally posted by marlo.

PAUL: Can you help on this :
topic.asp?TOPIC_ID=1235&FORUM_ID=13&CAT_ID=4&Topic_Title=twain+and+video+cap&Forum_Title=Beginners

from the ass of the world