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


Gender: 
Posts: 110
|
 |
Re: Multi-touch demo
« Reply #6 on: Mar 28th, 2016, 3:40pm » |
|
Brilliant, that works for single touches. Never seen type handle used before so I should have been more inquisitive about that.
Now to play with creating an array of structs. I am wondering if I can just stuff a struct with a sequence of six structs rather than Denis's more complex routine.
I progress it because we recently had a blind user who was interested in braille input, so six touch points would be ideal.
Thanks for the support.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Multi-touch demo
« Reply #7 on: Mar 28th, 2016, 4:01pm » |
|
on Mar 28th, 2016, 3:40pm, Rod wrote:| I am wondering if I can just stuff a struct with a sequence of six structs rather than Denis's more complex routine. |
|
You can, but you then lose the convenience of accessing the individual touch points by means of an array index (running from 0 to 5).
I am confident that Denis's code can be simplified. For example he allocates memory from Windows using GlobalAlloc followed by GlobalLock but that's an unnecessary complication: GlobalAlloc alone is fine so long as you pass the GMEM_FIXED flag.
After that he copies initial data into his structure array using RTLMoveMemory, but you don't need to do that either because there's no requirement to initialise the structures in the case of GetTouchInputInfo.
Once you've stripped out the unnecessary code you should find that it's quite manageable. I'd make the changes myself but this is an LBB forum so I'd obviously suggest you use that instead, and save both you and me (and the OP) the effort!
Quote:| I progress it because we recently had a blind user who was interested in braille input |
|
If that's Ray McAllister he's now fully converted to using LBB. There's not the slightest point making it run in LB for his benefit!
Richard.
|
|
|
|
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
|
|
|
|
|