******************
*** SIGN.PRG
******************
#include "FiveWin.ch"
#include "xbrowse.ch"
STATIC lSaved := .F.
REQUEST DBFCDX
FUNCTION CaptureSignature()
LOCAL oDlg, oSig, oSave, oClear, oPrint, oFinish, oBrush,;
lPaint := .F., cFile := Lower("signature.bmp"),;
cJpgFile := "signature.jpg", hDC, oGroup, oPadBrush,;
oImage
LOCAL aGradiate := {{1,CLR_WHITE, nRGB(188,211,175)},{1,CLR_WHITE, nRGB(188,211,175)}}
DEFINE BRUSH oPadBrush COLOR CLR_WHITE
DEFINE BRUSH oBrush GRADIENT aGradiate
DEFINE DIALOG oDlg RESOURCE "SIGN_PAD" BRUSH oBrush
DEFINE IMAGE oImage OF oDlg FILE cFile
REDEFINE SAY oSig PROMPT "" ID 101 OF oDlg COLOR CLR_BLUE, CLR_WHITE
oSig:lTransparent := .T.
REDEFINE BUTTON oSave ID 102 OF oDlg ;
PROMPT "&Save" ;
ACTION SaveToDisk(oSig, cFile, cJpgFile)
REDEFINE BUTTON oClear ID 103 OF oDlg ;
PROMPT "&Clear" ;
ACTION ( lPaint := .F., FillRect( hDC, GetClientRect( oSig:hWnd ), ;
oPadBrush:hBrush ), oSig:Refresh(.T.) )
REDEFINE BUTTON oPrint ID 104 OF oDlg ;
PROMPT "&Print" ;
ACTION PrintSignature()
REDEFINE BUTTON oFinish ID 105 OF oDlg ;
PROMPT "&Finish" ;
ACTION oDlg:End()
oSig:lWantClick := .T.
oSig:bLButtonUp := { | x, y, z | DoDraw( hDC, y, x, lPaint := .F. ) }
oSig:bMMoved := { | x, y, z | DoDraw( hDC, y, x, lPaint ) }
oSig:bLClicked := { | x, y, z | DoDraw( hDC, y, x, lPaint := .T., .T. ) }
ACTIVATE DIALOG oDlg CENTER ;
ON INIT hDC := GetDC( oSig:hWnd ) ;
VALID ( ReleaseDC( oSig:hWnd, hDC ), .T. )
RETURN nil
******************************************************************************
*** STATIC FUNCTION DoDraw( hDc, x, y, lPaint, lReset ) - To Draw Signature **
******************************************************************************
STATIC FUNCTION DoDraw( hDc, x, y, lPaint, lReset )
IF lReset != nil .and. lReset
MoveTo( hDC, x, y )
ENDIF
IF ! lPaint
MoveTo( hDC, x, y )
ELSE
LineTo( hDc, x, y )
ENDIF
RETURN nil
**********
FUNCTION SaveToDisk(oSig, cFile, cJpgFile)
oSig:SaveToBmp( cFile )
IF FILE(cFile)
*ShellExecute(,"OPEN", cFile,,,1)
FIConvertImageFile( cFile, cJpgFile, 2, 70 )
IF FILE(cJpgFile)
*MsgInfo(cJpgFile+" is saved to Disk.")
SaveToDbf(cJpgFile)
ELSE
MsgInfo(cJpgFile+" is not saved to Disk.")
ENDIF
ELSE
MsgInfo(cFile+" is not saved to Disk.")
ENDIF
RETURN nil
**********
FUNCTION SaveToDbf(cJpgFile)
LOCAL aStruct := {}
IF .NOT. FILE("sign.dbf")
aStruct := {{"party_id", "N", 5, 0},;
{"signature", "M",10, 0}}
DbCreate("sign.dbf",aStruct,"DBFCDX")
ENDIF
USE sign
IF EOF()
APPEND BLANK
ENDIF
IF RLock()
REPLACE party_id WITH 1,;
signature WITH MEMOREAD(cJpgFile)
DbUnLock()
MsgInfo("Signature is saved to Sign.Dbf. Now Print it.")
lSaved := .T.
ENDIF
RETURN nil
**********
FUNCTION PrintSignature()
LOCAL oPrn, cSignFile := "tempsign.jpg", cSignData
FIELD signature
CLOSE ALL
USE sign ALIAS sign VIA "DBFCDX"
IF MEMOWRIT(cSignFile,sign->signature)
PRINT oPrn PREVIEW
PAGE
oPrn:SayImage(10, 10, cSignFile, 1000 , 500,,.T. )
ENDPAGE
ENDPRINT
ELSE
MsgInfo("Signature TempFile not generated to Print.")
ENDIF
RETURN nil
*************