Retail POS

Tuesday, 20 January 2015

VFP Scanning using WIA.Common Dialog

Visual Foxpro & Scanning :

Visual Foxpro is having great feature to connect any hardware device  via windows class libraries, it may be  Dynamic link Library (.dll), Object Linking and Embedding OCX, Foxpro Link Library (.Fll) or Window API calls.

These all above need's proper syntax & calling method parameters to use in programming. Passing parameter type and function /procedure returning value type.

Now coming toward our scanning project.Here we will use a easy & common way of scanning a document in vfp using windows API  library call of "WIA.CommonDialog".

This library interacts with scanning or capturing device's driver provided by manufacturer of this device,  stores basic properties and relevant data as windows API interface.

Well different manufacture uses different methods & properties of their dll/ocx declaration. That is not our headace because we are not interacting their .dlls or ocx to get directly data from driver libraries.

We will use WIA.CommonDialog to get any device's list of  properties, names &  values  with VFP. This list of properties will help us to manage our desired out put format & relevent size of scanned document as our requirement.


* For adjusting properties of any device we have to communicate directly with device by calling functions of dll/ocx. WIA.CommonDialog will not allow to adjust properties values in some cases.

* Programe :   ReadScanner.prg
* Author :     witten by Zia Mughal

* CopyRight :  Pcland Software Inc. Pakistan

#DEFINE WIA_FORMAT_JPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
#DEFINE DPI = 150  && or what you want

LOCAL cdg As Object
cdg = CREATEOBJECT("Wia.CommonDialog")
DevMgr = CREATEOBJECT ("WIA.DeviceManager")

 dev = cdg.ShowSelectDevice

set printer to fullpath(sys(2003))+"\Property.txt"
set printer on
set device to printer

**  May your loop vary according to device properties
for i=1 to 33 step 1
a= dev.Properties(i).name
b= dev.Properties(i).value
? alltrim(str(i)) + " : "
??  alltrim(a) + " = "
?? b
set device to screen
set printer off
set printer to

modify file fullpath(sys(2003))+'\Property.txt' noedit
********assume example of HP scanjet g4050
* = 2  && 'Access Rights
* = 300  && 'DPI horizontal
* = 300  && 'DPI horizontal

* = 0 && 'x point to start scan
* = 0 && 'y point to start scan
* = 8.5 * DPI && 'Horizontal Extent
* = 11# * DPI && 'Vertical Extent for letter

Img = cdg.ShowAcquireImage
WAIT WINDOW TIMEOUT 1 "User Cancelled"


Enjoy the COFFEE!
My Respects!