Author |
Topic: Multi-touch demo (Read 19 times) |
|
Rod
Full Member
member is offline


Gender: 
Posts: 110
|
 |
Re: Multi-touch demo
« Reply #8 on: Mar 29th, 2016, 5:38pm » |
|
With a bit of help I managed to convert this to run in Liberty BASIC.
Code: ' Multi-touch demo by Richard Russell, http://www.rtrussell.co.uk/
' amended for Liberty BASIC by Brandon and Rod using Dennis McKinney's
' http://lbpe.wikispaces.com/ArraysAndStructs
' Uses WMLiberty.DLL (http://www.b6sw.com/forum/download.php?id=16)
'nomainwin
Global WM.TOUCH, hWnd, nPoints, ptrStructArray,sizeofTi
WM.TOUCH = hexdec("0240")
'a normal struct for the xy points
Struct pt, x As long, y As long
'a normal struct that will be used to define an array of structs
Struct ti, x As long, _
y As long, _
hSource As ulong, _
dwID As long, _
dwFlags As long, _
dwMask As long, _
dwTime As long, _
dwExtraInfo As long, _
cxContact As long, _
cyContact As long
'the size of the structure is
sizeofTi = Len(ti.struct)
'the amount of memory needed for the array is
maxPoints=6
memBlockSize = maxPoints*sizeofTi
'allocate memory and get pointer using Richards simplifications
'structs are accessed by sizeofTi offset
'so ti.struct=ptrStructArray+sizeofTi*i i=0-5
ptrStructArray = GlobalAlloc(memBlockSize)
Open "WMLiberty" For DLL As #wmlib
WindowWidth = 800
WindowHeight = 600
Open "Multi-touch demo" For graphics As #w
hWnd = hwnd(#w)
#w "trapclose quit"
#w "down; fill black ; backcolor red"
' set up callback to receive touch messages
callback lpwmtouch, wmtouch(ulong, ulong, ulong, ulong), long
calldll #wmlib, "SetWMHandler", hWnd As ulong, _
WM.TOUCH As ulong, _
lpwmtouch As ulong, _
1 As long, _
ret As long
' register the window for touch messaging
calldll #user32, "RegisterTouchWindow", hWnd As ulong, _
0 As ulong, _
lpwmtouch As ulong, _
ret As long
' now scan for messages
[wait] ' Must use a Scan loop.
Scan
Call plot
CallDLL #kernel32, "Sleep", 5 As Long, ret As Void
GoTo [wait]
Sub plot
For i = 0 To nPoints-1
'fill the ti.struct from the offset
ti.struct=ptrStructArray+sizeofTi*i
'get the screen coordinates
pt.x.struct = ti.x.struct / 100
pt.y.struct = ti.y.struct / 100
CallDLL #user32, "ScreenToClient", hWnd As ulong, _
pt As struct, _
ret As long
#w "place ";pt.x.struct;" ";pt.y.struct
#w "circlefilled 50"
Next i
nPoints = 0
End Sub
Sub quit h$
Close #wmlib
ret = GlobalFree(ptrStructArray)
Close #w
End
End Sub
Function wmtouch(hw, msg, wparam, lparam)
nPoints = wparam And hexdec("FFFF")
If nPoints > 6 Then nPoints = 6
CallDLL #user32, "GetTouchInputInfo", lparam As ulong, _
nPoints As ulong, _
ptrStructArray As ulong, _
sizeofTi As long, _
ret As long
CallDLL #user32, "CloseTouchInputHandle", lparam As ulong, _
ret As long
End Function
Function GlobalAlloc( dwBytes )
'returns pointer to fixed memory block.
CallDLL #kernel32, "GlobalAlloc", 0 As long, _
dwBytes As ulong, _
GlobalAlloc As long
End Function
Function GlobalFree( hMem )
CallDLL #kernel32, "GlobalFree", hMem As ulong, _
GlobalFree As long
End Function
|
| « Last Edit: Mar 30th, 2016, 08:19am by Rod » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Multi-touch demo
« Reply #9 on: Mar 29th, 2016, 9:29pm » |
|
on Mar 29th, 2016, 5:38pm, Rod wrote:| With a bit of help I managed to convert this to run in Liberty BASIC. |
|
It seems to work, although unlike my original the 'disks' don't disappear when you stop touching the screen - new ones just keep appearing on top.
As I'm sure you know, it's not necessary to open and close kernel32.dll: it's one of the standard DLLs that LB and LBB open for you and provide a ready-made handle to (#kernel32).
Richard.
|
|
Logged
|
|
|
|
Rod
Full Member
member is offline


Gender: 
Posts: 110
|
 |
Re: Multi-touch demo
« Reply #10 on: Mar 30th, 2016, 08:23am » |
|
Thanks made those changes in the above code, I took out the cls to make it obvious that the programmer is fielding a stream of these messages.
|
|
Logged
|
|
|
|
|