Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handling Pan Gestures - Resolved
Message
De
12/12/2014 07:49:54
Walter Meester
HoogkarspelPays-Bas
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Handling Pan Gestures - Resolved
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01612195
Message ID:
01612195
Vues:
108
J'aime (2)
Since there were no real solutions since my last post on "Slide gestures" I spend about a day on cracking this.
I knew it should be possible by hooking into the windows messaging system. The following is what I came up with.

It is just an example where a grid can be scrolled by a one-finger-pan on a touch screen (e.g tablet), but the example can easily be extended to support horizontal scrolling, zooming etc. Information on what is possible can be found on.

http://msdn.microsoft.com/en-us/library/windows/desktop/dd353242(v=vs.85).aspx

One finger pan, two finger pan, zooming, rotating, two finger tab can be detected and reacted upon.

I hope that someone will find this useful.
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN

*-

DEFINE CLASS form1 AS form
	Top = 0
	Left = 0
	Height = 500
	Width = 600
	lastx = 0
	lasty = 0
	addy = 0

	ADD OBJECT GestureEventHandler AS GestureEventHandler 

	ADD OBJECT grid1 AS grid WITH ;
		RecordSource = "Dummy", ;
		RecordSourceType = 1, ;
		Left = 5,;
		Height = 490,;
		Top = 5, ;
		Width = 690, ;
		AllowCellSelection = .F. 

	PROCEDURE handleevent(oGesture)

		IF oGesture.ID <> 4
			THIS.Lasty = 0
			THIS.addy = 0
		ENDIF

		IF THIS.LastY <> 0
			THIS.AddY = THIS.AddY +  (THIS.Lasty - oGesture.Ypos)/ THIS.Grid1.Rowheight
		ENDIF

		IF INT(THIS.AddY) <> 0
			FOR nT = 1 TO ABS(THIS.Addy)
				THIS.Grid1.DoScroll(IIF(THIS.AddY> 0,1,0))
			ENDFOR
			THIS.AddY = THIS.AddY% 1
		ENDIF 
		THIS.LastY = oGesture.Ypos
	ENDPROC

	*-

	PROCEDURE Load
		CREATE CURSOR Dummy (F1 I, F2 I, F3 I)
		FOR nT = 1 TO 1000
			INSERT INTO Dummy VALUES (nT, nT, nT)
			GO TOP
		ENDFOR
	ENDPROC

	FUNCTION Init
		THIS.GestureEventHandler.Setup(THISFORM.HWnd, THIS, "HandleEvent")
	ENDFUNC
ENDDEFINE

*-

DEFINE CLASS GestureEventHandler AS Custom

	FUNCTION Setup(nHwnd, oObject, cDelegate)
		LOCAL cStruct

		DECLARE SetGestureConfig IN user32.dll  integer, integer, integer, string @cStruct, integer
		DECLARE GetGestureInfo IN user32 integer, string @cStruct
		DECLARE integer GetWindowLong in Win32API integer hWnd, integer nIndex
		DECLARE integer CallWindowProc in Win32API integer lpPrevWndFunc, integer hWnd, integer Msg, integer wParam, integer lParam

		* Enable Single finger pan gesture
		cStruct = REPLICATE(CHR(0),4)+BINTOC(1,"4RS")+REPLICATE(CHR(0),4)
		=SetGestureConfig(nHWnd, 0, 1 , @cStruct, 12)

		BINDEVENT(nhWnd, 0x0119, THIS, "HandleEvent",4)
		BINDEVENT(THIS, "RaiseGestureEvent", oObject, cDelegate)
	ENDFUNC
	
	*-
	
	FUNCTION HandleEvent(nHwnd, nMsg, wParam, lParam)
		LOCAL nRet, lnOldProc, oGesture
	
		cStruct = BINTOC(48,"4RS")+REPLICATE(CHR(0),44)
		= GetGestureInfo(lParam, @cStruct)
	
		oGesture = CREATEOBJECT("Empty")
		ADDPROPERTY(oGesture, "Flags", CTOBIN(SUBSTR(cStruct,5,4),"4R"))
		ADDPROPERTY(oGesture, "hWnd", nHwnd)
		ADDPROPERTY(oGesture, "ID", CTOBIN(SUBSTR(cStruct,9,4),"4RS"))
		ADDPROPERTY(oGesture, "xPos", CTOBIN(SUBSTR(cStruct,17,2),"2RS"))
		ADDPROPERTY(oGesture, "yPos", CTOBIN(SUBSTR(cStruct,19,2),"2RS"))

		THIS.RaiseGestureEvent(oGesture)
		lnOldProc = GetWindowLong(nhWnd, -4)
		nRet  = CallWindowProc(lnOldProc, nhWnd, nMsg, wParam, lParam)
		RETURN nRet
	ENDFUNC
	
	*-
	
	FUNCTION RaiseGestureEvent(oGesture)
		* Do noting. It is just a placeholder for binding event.
	ENDFUNC
ENDDEFINE
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform