Using Say to draw

Using Say to draw

Postby reinaldocrespo » Wed Oct 08, 2008 9:13 pm

I recently read a post on the fwppc forum where a Tsay object is used to capture a signature using mouse movement. I've made some changes to suit my needs:

Code: Select all  Expand view
function CaptureSignaure( oOwner )
local oDlg, ;
      oSig, ;
      nHdc, ;
      nOldX := -1, ;
      nOldY := -1, ;
      cFile := lower( GetTempDir() + "\signature.bmp" )

   DEFINE DIALOG oDlg TITLE "Signature" OF oOwner FROM 0,0 TO 150,350 PIXEL

   @ 15, 5 SAY oSig PROMPT "" SIZE 150, 40 PIXEL BORDER OF oDlg
   @ 01, 5 BUTTON "Clear" SIZE 25, 10 PIXEL ACTION oSig:refresh(.t.) OF oDlg
   @ 01, 60 BUTTON "Save" SIZE 25, 10 PIXEL OF odlg ACTION ;
      ( oSig:saveToBmp( cfile ), ;
      oSig:refresh(.t.), ;
      ReleaseDC( oSig:hWnd, oSig:hDC ), oDlg:end() )

   nHdc := GetDC( oSig:hWnd )

   oSig:bLButtonUp := { |x,y,z| DoDraw( nHdc, y+1, x+1,@noldx,@noldy ), nOldX := -1, nOldY := -1 }
   oSig:bMMoved := { |x,y,z| DoDraw( nHdc, y, x ,@noldx,@noldy) }
   oSig:bLClicked := { |x,y,z| DoDraw( nHdc, y, x ,@noldx,@noldy) }

   ACTIVATE DIALOG oDlg CENTER

return cFile

*------------------------------------------------------------------------------------------
STATIC Function DoDraw( hDc, x, y, noldx, noldy )

   If nOldX == -1 .And. nOldY == -1
      nOldX := x
      nOldY := y
      MoveToEx( hDC, x, y )
   Else
      LineTo( hDc,x,y )
   EndIf

RETURN Nil

*------------------------------------------------------------------------------------------
DLL STATIC FUNCTION MoveToEx( hWnd AS HDC, nX AS _INT, nY AS _INT, NULL AS _INT ) AS BOOL PASCAL LIB "coredll.dll"


But it does not work with fwh. Can someone help?



Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Postby yury » Thu Oct 09, 2008 9:34 pm

hello Mr.Reinaldo,

I dont have the coredll.dll , so I can´t make a 100 % test... (I rem the call of the function MoveToEx)

I add this on your code:

oSig:lWantClick = .T.

before the activate the dialog, and the program draws a line, when I move the mouse, but not in the center of dialog (maybe because I dont use MoveToEx)

regards
Yury Marcelino Al
yury030575@yahoo.com.br
vimansca@vimansca.com.br
Leme / SP - Brasil
yury
 
Posts: 56
Joined: Wed May 23, 2007 2:01 pm

Postby Antonio Linares » Thu Oct 09, 2008 10:38 pm

Reinaldo,

Here it is :-)

signatur.prg
Code: Select all  Expand view
#include "FiveWin.ch"

function CaptureSignature()

   local oDlg, oSig, lPaint := .F., cFile := Lower( "signature.bmp" ), hDC

   DEFINE DIALOG oDlg TITLE "Signature" FROM 0, 0 TO 150, 350 PIXEL

   @ 15, 5 SAY oSig PROMPT "" SIZE 150, 40 PIXEL BORDER OF oDlg
   
   @ 01, 5 BUTTON "Clear" SIZE 25, 10 PIXEL ACTION oSig:refresh(.t.) OF oDlg
   
   @ 01, 60 BUTTON "Save" SIZE 25, 10 PIXEL OF odlg ;
      ACTION ( oSig:SaveToBmp( cFile ), oDlg:End() )

   oSig:lWantClick := .T.
   oSig:bLButtonUp := { | x, y, z | DoDraw( hDC, y+1, x+1, lPaint := .F. ) }
   oSig:bMMoved    := { | x, y, z | DoDraw( hDC, y, x , lPaint ) }
   oSig:bLClicked  := { | x, y, z | DoDraw( hDC, y, x, lPaint := .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 )

   if ! lPaint
      MoveTo( hDC, x, y )
   else
      LineTo( hDc, x, y )
   endIf

return nil
regards, saludos

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

Postby reinaldocrespo » Thu Oct 09, 2008 10:55 pm

Antonio;

Sorry for the double posting and thank you for the solution.


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Using Say to draw

Postby HunterEC » Sat Apr 25, 2009 6:36 am

Antonio:

Can this program work with another input device besides the mouse ? Thank you.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 96 guests