Scanner

Scanner

Postby Ehab Samir Aziz » Fri Oct 14, 2005 2:01 pm

How can I use scanners with FW ?
Gice an Example from the sample directory .
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

It may help

Postby dutch » Sun Oct 16, 2005 2:22 pm

Hi Ehab Samir Aziz,

This is Tscanner class for FW 16bit. I hope it help.

Regards,
Dutch

Code: Select all  Expand view  RUN
/*------------------------------------------------------------------------*
     ฺฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฟ
   ณ                                                                   ณ
   ณ ProcName......: Scanner.prg                                       ณ
   ณ Pourpose......: TWAIN standard device Class interface             ณ
   ณ Date..........: 05-11-96                                          ณ
   ณ Author........: (c),L.Gadaleta                                    ณ
   ณ                                                                   ณ
   ภฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤฤู
   
*------------------------------------------------------------------------*/

#include "FiveWin.ch"

#define STAND_ALONE

#define TWAIN_DLL               "DMTwain.dll"

STATIC oWnd

#ifdef STAND_ALONE

FUNCTION ScanMe(cFileRes)

   /*
        FUNCTION Main(cFileRes)
      cFileRes = "C:\PATH\FILENAME.BMP , 150"       
      .OR.
      cFileRes = "C:\PATH\FILENAME.BMP"       // Dpi Will be 100 (default value)
   */

   LOCAL cFile, nRes, n
        cFile := cFileRes
   if !cFileRes == NIL
      if ( n:=AT(",",cFileRes) ) > 0
         cFile := Alltrim(Substr(cFileRes,1,n-1))
         nRes  := Val(Alltrim(Substr(cFileRes,n+1)))
      end
   end

        nRes  := 100

        CursorWait()

        DEFINE WINDOW oWnd FROM 1,1 TO 1,1
        ACTIVATE WINDOW oWnd ON INIT (oWnd:Hide(), RunScan(cFile,oWnd:hWnd,nRes))

        CursorArrow()

RETURN NIL

   STATIC FUNCTION RunScan(cFile,hWnd,nRes)
   LOCAL oScanner := Scanner():New(hWnd)
   DEFAULT nRes := 100               // Scanner resolution in Dpi
        oScanner:Set(.F.)                                               // Set User Interface Off
   oScanner:DigiToFile(cFile,nRes)   // Acquires
   oScanner:End()
   oWnd:End()
        RETURN NIL

#endif

CLASS Scanner
   DATA   hWnd   AS NUMERIC   // Handle of the window
   DATA   hDll   AS NUMERIC   // Handle of the DLL
   DATA   lLoad   AS LOGICAL   //   .T. DLL & Driver Loaded
   DATA   hDib   AS NUMERIC   // Current Dib handle
   *
   METHOD New()         CONSTRUCTOR
   METHOD End()
   METHOD Set()            // Acquiring Dialog ON/OFF
   METHOD Choose()         // Select Image Device Source
   METHOD DigiToFile()      // Acquire Image and save to a file
   METHOD DigiToClip()      // Acquire Image and copy to ClipBoard
   METHOD SetResolution()   // Set Dpi for the scanner
   *
   PROTECTED :
      METHOD Free()         // Release Dib's handle
      METHOD IsActive()      // Twain Driver Loaded
      METHOD Register()      // Register my application into Twain application
      METHOD DibToFile()   // Write to file Dib's handle in BMP format
END CLASS

METHOD New(hWnd)
// Constructor
::hWnd := iif( ValType( hWnd ) == "N" , hWnd , 0 )
::lLoad := .T.
::hDLL := LoadLibrary( TWAIN_DLL )
::hDib := 0
if ::hDll <= 21
   ::lLoad := .F.
   MsgAlert( BuildError(::hDll) , TWAIN_DLL )
   RETU Self
end
if ( ::lLoad := ::IsActive() )
   ::Register()
end
RETU Self

METHOD End()
// Destructor
if ::hDib != 0
   ::Free( ::hDib )
end
FreeLibrary( ::hDll )
RETU NIL

METHOD DigiToFile( cFile , nRes )
// Acquire Document & save to file
LOCAL nPixType := 0
LOCAL cFarProc
DEFAULT nRes := 100

::SetResolution( nRes )

if ::lLoad
   cFarProc := GetProcAddress( ::hDLL, "TWAIN_AcquireNative",.T., WORD,WORD,_INT )
   ::hDib  := CallDLL( cFarProc,::hWnd,nPixType )
   if ::hDib == 0
                MsgInfo("Cannot Load Image, Scanner not found","")
   else
      ::DibToFile(::hDib,cFile)
      ::Free( ::hDib )
   end
end
RETU Self

METHOD DigiToClip()
// Acquire document & copy to ClipBoard
LOCAL nPixType := 0
LOCAL cFarProc
LOCAL nResult
if ::lLoad
   cFarProc := GetProcAddress( ::hDLL, "TWAIN_AcquireToClipBoard",.T., _INT,WORD,_INT )
   nResult  := CallDLL( cFarProc,::hWnd,nPixType )
end
RETU Self

METHOD SetResolution( nDpi )
// NEW
LOCAL cFarProc
LOCAL uResult
DEFAULT nDpi := 100
if ::lLoad
   cFarProc := GetProcAddress( ::hDLL, "TWAIN_SetResolution",.T., VOID,_DOUBLE )
   uResult  := CallDLL( cFarProc,nDpi )
end
RETU Self

METHOD Set(lShow)
// Show-Hide Scanner's Dialog Box
LOCAL nHide := 0      // Default: Shows Scanner's Dialog Box
LOCAL cFarProc
LOCAL uResult
DEFAULT lShow := .T.
if ::lLoad
   nHide := iif(lShow,0,1)
   cFarProc := GetProcAddress( ::hDLL, "TWAIN_SetHideUI",.T., VOID,_INT )
   uResult  := CallDLL( cFarProc,nHide )
end
RETU Self

METHOD Choose()
// Select Image Device Source
LOCAL cFarProc
LOCAL nResult
if ::lLoad
   cFarProc := GetProcAddress( ::hDLL, "TWAIN_SelectImageSource",.T., _INT,WORD )
   nResult  := CallDLL( cFarProc,::hWnd )
end
RETU Self

//---------- Protected Methods

   METHOD Free(hDib)
   // Release Dib's Handle
   LOCAL cFarProc
   LOCAL uResult
   cFarProc := GetProcAddress( ::hDLL, "TWAIN_FreeNative",.T., VOID,WORD )
   uResult  := CallDLL( cFarProc,hDib )
   RETU NIL

   METHOD DibToFile(hDib,cFile)
   // Write to File From DIB's handle
   LOCAL cFarProc
   LOCAL nResult
   LOCAL lRet
   cFarProc := GetProcAddress( ::hDLL, "TWAIN_WriteNativeToFilename",.T., _INT,WORD,LPSTR)
   lRet     := ( (nResult:=CallDLL( cFarProc,hDib,cFile ))==0 )
   DO CASE
      CASE nResult == -1
         MsgInfo("Annullato dall'utente","File non registrato")
      CASE nResult == -2
         MsgInfo("Errore durante la scrittura sul file "+cFile,"File non registrato")
      CASE nResult == -3
         MsgInfo("Errore interno sul file DIB","File non registrato")
      CASE nResult == -4
         MsgInfo("Errore durante la scrittura sul file "+cFile+", probabile spazio insufficiente sul disco !","File non registrato")
   ENDCASE
   RETU lRet

   METHOD IsActive()
   // Is Twain driver loaded ?
   LOCAL cFarProc
   LOCAL nResult
   cFarProc := GetProcAddress( ::hDLL, "TWAIN_IsAvailable",.T., _INT )
   if ! (nResult    := CallDLL( cFarProc )) == 1
      MsgAlert("Nessun driver per apparecchi TWAIN compatibili risulta disponibile !","Errore hardware")
      // Messaggio inviato direttamente da TWAIN.DLL
   end
   RETU iif(nResult==1,.T.,.F.)

   METHOD Register()
   // Register my application into Twain application
   LOCAL   nMaiorNum := 1
   LOCAL nMinorNum := 0   // Result -> 1.0
   LOCAL nLanguage := 0
   LOCAL nCountry  := 0
   LOCAL cVersion  := "1.0"
   LOCAL cManifact := "The Genius"
   LOCAL cFamily   := "Digitizer"
   LOCAL cProduct := StrTran(cFileName(GetModuleFileName(GetInstance())),".EXE","")
   LOCAL cFarProc
   LOCAL uResult
   cFarProc := GetProcAddress( ::hDLL, "TWAIN_RegisterApp",.T.,;
                           VOID,_INT,_INT,_INT,_INT,LPSTR,LPSTR,LPSTR,LPSTR )
   uResult  := CallDLL( cFarProc,nMaiorNum,nMinorNum,nLanguage,nCountry,cVersion,cManifact,cFamily,cProduct )
   RETU NIL

//---------- END Protected Methods

STATIC FUNCTION BuildError(nError)
LOCAL cRet := "Errore nella libreria dinamica"
DO CASE
   CASE nError == 0
         cRet := "Memoria insufficiente ad eseguire il programma"
   CASE nError == 2
         cRet := "File non trovato"
   CASE nError == 3
         cRet := "Percorso non trovato"
   CASE nError == 5
         cRet := "Tentantivo di collegarsi dinamicamente ad un task o errore di condivisione"
   CASE nError == 6
         cRet := "La libreria richiede un segemento separato per ogni task"
   CASE nError == 8
         cRet := "Memoria insufficiente ad avviare l'applicazione"
   CASE nError == 10
         cRet := "Versione di MS Windows non corretta"
   CASE nError == 11
         cRet := "Libreria non valida oppure non Š un'applicazione MS Windows"
   CASE nError == 12
         cRet := "Applicazione disegnata per un sistema operativo diverso"
   CASE nError == 13
         cRet := "Applicazione disegnata per MS-DOS 4.0"
   CASE nError == 14
         cRet := "Tipo di file eseguibile sconosciuto"
   CASE nError == 15
         cRet := "Tentativo di caricare un'applicazione disegnata per funzionare in modalit… reale"
   CASE nError == 16
         cRet := "Tentativo di caricare una seconda istanza dell'applicazione contenente segmenti di dati multipli non marcati per la sola lettura"
ENDCASE
RETU OemToAnsi( cRet + "!" )
User avatar
dutch
 
Posts: 1550
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Postby driessen » Wed Oct 19, 2005 12:18 am

Is it possible to translate the message to English ?

Can you tell me where the file DMTwain.dll can be found ? Or can you send me a copy of this file ?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

tscanner problem (scan all include backgroup area)

Postby dutch » Wed Oct 19, 2005 4:39 pm

Dear All,

I use tscanner with DMTwain.dll but it has some problem with some scanner machine. I've used Hp SJ3300c in my office, it works fine but other machine such as Hp SJ2400 does not crop the image area when I scan. For example when I scan my ID card with Hp Director, it crop the image only my ID card area (118Kb) but the tscanner from my program scan all area include white backgroup (almost 3 Mb). I try to setting Automatic crop in Hp Director Setting but it has no effect.

Thanks for any help and idea,
Dutch
User avatar
dutch
 
Posts: 1550
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Postby RAMESHBABU » Sun Apr 02, 2006 1:09 pm

Mr.Dutch

Can I get a copy of DMTwain.dll.

Please send it to: aksharasoft@hotmail.com

TIA

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Sun Apr 02, 2006 3:22 pm

Please use www.hyperupload.com to attach files here. Thanks.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for CA-Clipper

Who is online

Users browsing this forum: No registered users and 13 guests