1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
Imports System.Runtime.InteropServices
Imports System.Security.Permissions
Public Class Form1
Private Const WM_GESTURE As Integer = &H11A
Private Const WM_TOUCH As Integer = &H240
Private Const TOUCHEVENTF_MOVE As Integer = &H1
Private Enum RegisterTouchWindowFlags
TWF_FINETOUCH = &H1
TWF_WANTPALM = &H2
End Enum
Private Structure TOUCHINPUT
Dim X As Integer
Dim Y As Integer
Dim hSource As Integer
Dim dwID As Integer
Dim dwFlags As Integer
Dim dwMask As Integer
Dim dwTime As Integer
Dim dwExtraInfo As Integer
Dim cxContact As Integer
Dim cyContact As Integer
End Structure
Private touchInputSize As Integer
Dim points(10) As Point
Private WithEvents mySubClass As New clsSubClass
Private Declare Function RegisterTouchWindow Lib "user32.dll" (ByVal hWnd _
As System.IntPtr, Optional ByVal ulFlags As RegisterTouchWindowFlags = 0) As _
Integer
Private Declare Function GetTouchInputInfo Lib "user32" (ByVal hTouchInput As System.IntPtr, ByVal cInputs As Integer, _
<[In](), Out()> ByVal pInputs As TOUCHINPUT(), ByVal cbSize As Integer) As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Me.Left = -1000 'A SUPPRIMER SI UN SEUL ECRAN
Infos.Show()
Dim hWndBtn As Integer = 0
mySubClass.Add(Panel1.Handle, "Panel1")
hWndBtn = RegisterTouchWindow(Panel1.Handle, 0)
Button1.Text = Str(hWndBtn)
touchInputSize = Marshal.SizeOf(New TOUCHINPUT())
End Sub
Private Sub mySubClass_WinProc(ByVal Index As Integer, ByVal Key As String, _
ByRef m As System.Windows.Forms.Message) Handles mySubClass.WinProc
If m.Msg = WM_TOUCH Then
Dim inputCount As Integer = m.WParam.ToInt32 And &HFFFF
Dim inputs() As TOUCHINPUT
inputs = New TOUCHINPUT(inputCount) {}
If Not GetTouchInputInfo(m.LParam, inputCount, inputs, touchInputSize) Then
Exit Sub
End If
For i As Integer = 0 To inputCount - 1
Dim ti As TOUCHINPUT = inputs(i)
If (ti.dwFlags And TOUCHEVENTF_MOVE) <> 0 Then
Dim pt As Point = PointToClient(New Point(ti.X / 100, ti.Y / 100))
If pt <> points(i) Then
Dim ptdown As Point = PointToClient(New Point(ti.X / 100, ti.Y / 100))
points(i) = ptdown
Infos.TB_infos.AppendText("Move" & i.ToString & ": " & pt.X.ToString & " x " & pt.Y.ToString & vbCrLf)
End If
End If
Next i
m.Msg = 0
End If
End Sub
End Class
Public Class clsSubClass
Private iList As New List(Of SubClassItem)
Public Event WinProc(ByVal Index As Integer, ByVal Key As String, ByRef m _
As Message)
Private Class SubClassItem
Inherits System.Windows.Forms.NativeWindow
Public m_Key As String
Public Event WinProc(ByVal sender As SubClassItem, ByRef m As Message)
Public Sub New(ByVal Handle As IntPtr, ByVal Key As String)
MyBase.AssignHandle(Handle)
m_Key = Key
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
RaiseEvent WinProc(Me, m)
MyBase.WndProc(m)
End Sub
End Class
Public Sub Add(ByVal Handle As IntPtr, ByVal Key As String)
Dim c As New SubClassItem(Handle, Key)
AddHandler c.WinProc, AddressOf ItemWinProc
iList.Add(c)
End Sub
Private Sub ItemWinProc(ByVal sender As SubClassItem, ByRef m As Message)
RaiseEvent WinProc(iList.IndexOf(sender), sender.m_Key, m)
End Sub
End Class |
Partager