#include "FiveWin.ch"
function CaptureSignature()
local oDlg, oSig, lPaint := .F., cFile := Lower( "signature.bmp" ), hDC
local lReset := .f.
local oBrush
local nPenWidth := 4, oPenSig
local nTop := 2, nBottom := 0
local aCoord
local nColor := CLR_WHITE
oBrush := TBrush():New( , nColor )
DEFINE DIALOG oDlg TITLE "Signature" PIXEL ;
RESOURCE "DLG_Sign"
DEFINE PEN oPenSig WIDTH nPenWidth COLOR CLR_BLACK
REDEFINE SAY oSig ID 200 PROMPT "" OF oDlg
oSig:nClrPane := nRgb( 255,255,255 )
oSig:oBrush := oBrush
redefine button prompt 'Save';
id 100 of oDlg update;
ACTION ( oSig:SaveToBmp( cFile ), oDlg:End() )
redefine button prompt 'Cancel';
id 101 of oDlg ;
action ( lReturn := .f., oDlg:End() )
redefine button prompt 'Clear';
id 102 of oDlg ;
action ( lPaint := .F., ;
FillRect( hDC, GetClientRect( oSig:hWnd ), oBrush:hBrush ), ;
oSig:refresh(.t.) )
oSig:lWantClick := .T.
// Fixed row, col to y, x conversion, x/y designation was reversed
oSig:bLButtonUp := { | y, x, z | DoDraw( hDC, x, y, lPaint := .F.,, oPenSig ) }
// Added limits to Top and Bottom in case users draw off canvas
oSig:bMMoved := { | y, x, z | ( ;
if( y >= nBottom .or. y <= nTop , lReset := .T., lReset := .f. ), ;
DoDraw( hDC, x, y , lPaint, lReset, oPenSig )) }
oSig:bLClicked := { | y, x, z | DoDraw( hDC, x, y, lPaint := .T., .t., oPenSig ) }
// If button released when not on Signature area
oDlg:bLButtonUp := { || lPaint := .F. }
ACTIVATE DIALOG oDlg CENTER ;
ON INIT ( aCoord := GetCoors( oSig:hWnd ), ;
nBottom := aCoord[3]- aCoord[1]-2, ;
hDC := GetDC( oSig:hWnd ), oSig:nClrPane := nColor ) ;
VALID ( ReleaseDC( oSig:hWnd, hDC ), .T. )
RELEASE PEN oPenSig
return nil
static function DoDraw( hDc, x, y, lPaint, lReset, oPen )
if ! lPaint .or. ( lReset != nil .and. lReset )
MoveTo( hDC, x, y )
else
LineTo( hDc, x, y, oPen:hPen )
endIf
return nil