IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

MultiTouch WinForm VB


Sujet :

VB.NET

  1. #1
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 18
    Points
    18
    Par défaut MultiTouch WinForm VB
    Bonjour,

    Personne a réussi à faire du multitouch en vb.net ?
    Pour le moment j'arrive à détecter que je suis en train de faire un Zoom ou une Rotation avec deux doigts mais je n'arrive pas a avoir les coordonnées des deux doigts en même temps...
    C'est le dernier qui bouge qui donne les points !

    Merci à vous.

  2. #2
    Membre habitué
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cher (Centre)

    Informations forums :
    Inscription : Mars 2011
    Messages : 105
    Points : 153
    Points
    153
    Par défaut
    Bonjour,

    J'ai aussi développé un programme en VB et winform principalement destiné à une tablette sous windows (mais aussi sur un PC avec écran non tactile).
    J'ai rencontré le même manque de doc (surtout en vb !).
    Comme j'avais principalement besoin de la gestion des gestes (Pans, Zooms, pressAndTap etc..) j'ai laissé tomber les messages obtenus après WM_TOUCH pour me concentrer sur ceux de WM_GESTURE.
    Il est impossible d'avoir les deux types de message en même temps.

    Une petite astuce avec WM_PARENTNOTIFY (qui fonctionne en même temps que WM_GESTURE) m'a permit de connaître le nombre de doigts touchant la tablette ce qui me permet d'affiner l'usage de messages comme GID_TWOFINGERTAP qui, contrairement à son nom, fonctionne indifféremment avec une frappe de deux, trois, quatre..... doigts.

  3. #3
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    Tu peux voir ce lien github:
    https://github.com/rprouse/WinTouch.NET

  4. #4
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 18
    Points
    18
    Par défaut
    Citation Envoyé par baloub Voir le message
    Bonjour,

    J'ai aussi développé un programme en VB et winform principalement destiné à une tablette sous windows (mais aussi sur un PC avec écran non tactile).
    J'ai rencontré le même manque de doc (surtout en vb !).
    Comme j'avais principalement besoin de la gestion des gestes (Pans, Zooms, pressAndTap etc..) j'ai laissé tomber les messages obtenus après WM_TOUCH pour me concentrer sur ceux de WM_GESTURE.
    Il est impossible d'avoir les deux types de message en même temps.

    Une petite astuce avec WM_PARENTNOTIFY (qui fonctionne en même temps que WM_GESTURE) m'a permit de connaître le nombre de doigts touchant la tablette ce qui me permet d'affiner l'usage de messages comme GID_TWOFINGERTAP qui, contrairement à son nom, fonctionne indifféremment avec une frappe de deux, trois, quatre..... doigts.
    Idem, je bloque juste sur les coordonnées des deux doigts en même temps ! Franchement si prêt du but je suis vraiment dégoûté

  5. #5
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 18
    Points
    18
    Par défaut
    Citation Envoyé par MABROUKI Voir le message
    bonjour

    Tu peux voir ce lien github:
    https://github.com/rprouse/WinTouch.NET
    Malheureusement cela fonctionne que en C#

  6. #6
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 18
    Points
    18
    Par défaut
    Citation Envoyé par baloub Voir le message
    Bon, en fait je faisais une erreur d'interprétation.
    Je ne sais pas pourquoi mais je pensais que WM_POINTERDOWN fonctionnait comme GID_ZOOM et renvoyait les coordonnées d'un point milieu.

    En fait non, on reçoit autant de messages WM_POINTERDOWN que de contacts de doigts :
    - un doigt -> un message avec coordonnées
    - deux doigts -> deux messages avec coordonnées de chaque point
    - trois doigts -> trois messages etc..

    Du coup il suffit de stocker les coordonnées reçues dans une liste, puis lors d'un mouse move suivant (ou un GID_PAN) de compter le nombre de points dans la liste et d'appliquer la bonne action.
    Je suis tombé sur ce message, tu as donc pu y faire marcher ?

  7. #7
    Membre habitué
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cher (Centre)

    Informations forums :
    Inscription : Mars 2011
    Messages : 105
    Points : 153
    Points
    153
    Par défaut
    Bonjour,

    C'est "l'astuce" dont je parlais.
    Je voulais connaître le nombre de points de contact ainsi que les coordonnées dans le cas d'un contact unique.
    Si tu as besoin de connaître l'évolution du multi touch dans le temps c'est vers WM_TOUCH qu'il faut t'orienter.
    Ci-dessous le principe de la routine:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
        <PermissionSet(SecurityAction.Demand, Name:="FullTrust")>
        Protected Overrides Sub WndProc(ByRef m As Message)
           Try
                Select Case m.Msg
     
                    Case WM_DISPLAYCHANGE ' traitement suivant un changement de dimensions d'écran (ou rotation)
                        Dim WEcran As Integer = m.LParam.ToInt64 And &HFFFF
                        Dim HEcran As Integer = (m.LParam.ToInt64 >> 16) And &HFFFF
                        traite_orientation(WEcran, HEcran)
                        handled = True
     
                    Case WM_GESTURE  ' traitement des messages gestuels (zoom, pan...)
                        handled = DecodeGesture(m)
                        Exit Select
     
                    Case WM_PARENTNOTIFY
                        Dim vwparam As Integer = m.WParam.ToInt32 And &HFFFF
                        If vwparam = WM_POINTERDOWN Then
                            tactile = True '
                            Dim xp As Integer = (m.LParam.ToInt32) And &HFFFF
                            Dim yp As Integer = (m.LParam.ToInt32) >> 16
                            Dim obj As Control = FromHandle(WindowFromPoint(New Point(xp, yp))) ' détermine le control qui a été touché
                            PiBoxTouche = obj.Name 
                            Dim coor As Point = obj.PointToClient(New Point(xp, yp)) 'coordonnées du point en valeurs client
     
                            '
                            '
                            ' ici tout un tas de select case en fonction de l'objet touché
                            '
                            '
     
     
                            memoTouch.Add(coor) 'mémo des coordonnées du point touché par un doigt
                            nbDoigts = memoTouch.Count ' mémo du nombre de doigts 
     
                            ' Le timer est de 50ms suffisant pour comptabiliser le nb de doigts avant de vider la liste
     
                            If Timer_MultiDoigts.Enabled = False Then 
                                Timer_MultiDoigts.Start()
                            End If
     
                         End if
                 End Select
             MyBase.WndProc(m)
        End Sub
     
        Private Sub Timer_MultiDoigts_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer_MultiDoigts.Tick
            Timer_MultiDoigts.Stop()
            memoTouch.Clear()
        End Sub

  8. #8
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 18
    Points
    18
    Par défaut
    Ok, mais dans tous les cas tu n'auras jamais les coordonnées deux doigts en même temps.
    En plus de ça c'est le dernier doigt qui bouge qui a raison et les coordonnées sont flou car elles correspondent au premier.
    Bord** de winform !

  9. #9
    Membre habitué
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cher (Centre)

    Informations forums :
    Inscription : Mars 2011
    Messages : 105
    Points : 153
    Points
    153
    Par défaut
    Si tu veux les coordonnées de chaque contact et leur évolutions il faut WM_TOUCH.
    J'ai regardé le programme d'exemple de MS en C# et j'ai converti la partie acquisition des points en VB.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    Imports System.Runtime.InteropServices
    Imports System.Security.Permissions
    Public Class Form1
     
        Private Const WM_TOUCH As Integer = &H240
        Private Const TOUCHEVENTF_MOVE As Integer = &H1
        Private Const TOUCHEVENTF_DOWN As Integer = &H2
        Private Const TOUCHEVENTF_UP As Integer = &H4
        Private Const TOUCHEVENTF_INRANGE As Integer = &H8
        Private Const TOUCHEVENTF_PRIMARY As Integer = &H10
        Private Const TOUCHEVENTF_NOCOALESCE As Integer = &H20
        Private Const TOUCHEVENTF_PEN As Integer = &H40
        Private Const TOUCHINPUTMASKF_TIMEFROMSYSTEM As Integer = &H1
        Private Const TOUCHINPUTMASKF_EXTRAINFO As Integer = &H2
        Private Const TOUCHINPUTMASKF_CONTACTAREA As Integer = &H4
     
        <StructLayout(LayoutKind.Sequential)>
        Public Structure TOUCHINPUT
            Public x As Integer
            Public y As Integer
            Public hSource As System.IntPtr
            Public dwID As Integer
            Public dwFlags As Integer
            Public dwMask As Integer
            Public dwTime As Integer
            Public dwExtraInfo As System.IntPtr
            Public cxContact As Integer
            Public cyContact As Integer
        End Structure
     
        Declare Function RegisterTouchWindow Lib "user32.dll" (ByVal hWnd As System.IntPtr, ByVal ulFlags As UInteger) As Boolean
        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
        Declare Sub CloseTouchInputHandle Lib "user32" (ByVal lParam As System.IntPtr)
     
        Private touchInputSize As Integer
     
        <PermissionSet(SecurityAction.Demand, Name:="FullTrust")>
        Protected Overrides Sub WndProc(ByRef m As Message)
            Dim handled As Boolean
     
            Select Case m.Msg
                Case WM_TOUCH
                    handled = DecodeTouch(m)
                Case Else
                    handled = False
            End Select
     
            MyBase.WndProc(m)
     
            If handled Then
                m.Result = New System.IntPtr(1)
            End If
        End Sub
     
        Dim points(10) As Point
     
        Private Function DecodeTouch(ByRef m As Message) As Boolean
            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
                Return False
                Exit Function
            End If
     
            For i As Integer = 0 To inputCount - 1
                Dim ti As TOUCHINPUT = inputs(i)
                If (ti.dwFlags And TOUCHEVENTF_DOWN) <> 0 Then
                    Dim pt As Point = PointToClient(New Point(ti.x / 100, ti.y / 100))
                    Infos.TB_infos.AppendText("Down" & i.ToString & ": " & pt.X.ToString & " x " & pt.Y.ToString & vbCrLf)
                    points(i) = pt
                ElseIf (ti.dwFlags And TOUCHEVENTF_UP) <> 0 Then
                    Dim pt As Point = PointToClient(New Point(ti.x / 100, ti.y / 100))
                    Infos.TB_infos.AppendText("Up" & i.ToString & ": " & pt.X.ToString & " x " & pt.Y.ToString & vbCrLf)
                    points(i) = pt
                ElseIf (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
                        Infos.TB_infos.AppendText("Move" & i.ToString & ": " & pt.X.ToString & " x " & pt.Y.ToString & vbCrLf)
                    End If
                    points(i) = pt
                End If
            Next
            CloseTouchInputHandle(m.LParam)
            Return True
        End Function
     
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            touchInputSize = Marshal.SizeOf(New TOUCHINPUT())
            Infos.Show()
            Try
     
                If Not RegisterTouchWindow(Me.Handle, 0) Then
                    Infos.TB_infos.Text = "ERROR: Could not register window for multi-touch"
                End If
     
            Catch exception As Exception
                Infos.TB_infos.Text = "ERROR: RegisterTouchWindow API not available"
                Infos.TB_infos.AppendText(exception.ToString())
            End Try
        End Sub
    End Class
    Le programme ouvre deux fenêtres. La première sert à capter les touchés, la seconde affiche les coordonnées de chaque point de contact.

    En pièce jointe la solution pour Visual Studio 2019 (l'exécutable est dans "Bin\Debug")
    Fichiers attachés Fichiers attachés

  10. #10
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 18
    Points
    18
    Par défaut
    Merci pour l'info, je regarde ça et je te tiens au courant ;-)

  11. #11
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 18
    Points
    18
    Par défaut
    Je viens de tester ton code qui marche parfaitement avec vb2008 d'ailleurs...
    Par contre WM_TOUCH fonctionne que sur la form et non sur un object enfant
    Si tu poses un panel par exemple le WM_TOUCH n'arrive jamais.

  12. #12
    Membre habitué
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cher (Centre)

    Informations forums :
    Inscription : Mars 2011
    Messages : 105
    Points : 153
    Points
    153
    Par défaut
    Effectivement, ça ne marche que sur la form...

    J'ai modifié un peu le code pour introduire un début de gestion de gestes.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
     
    Imports System.Runtime.InteropServices
    Imports System.Security.Permissions
    Public Class Form1
     
        Private Const WM_TOUCH As Integer = &H240
        Private Const WM_GESTURE As Integer = 281
        Private Const WM_GESTURENOTIFY As Integer = 282
        Private Const WM_PARENTNOTIFY As Integer = 282
        Private Const TOUCHEVENTF_MOVE As Integer = &H1
        Private Const TOUCHEVENTF_DOWN As Integer = &H2
        Private Const TOUCHEVENTF_UP As Integer = &H4
        Private Const TOUCHEVENTF_INRANGE As Integer = &H8
        Private Const TOUCHEVENTF_PRIMARY As Integer = &H10
        Private Const TOUCHEVENTF_NOCOALESCE As Integer = &H20
        Private Const TOUCHEVENTF_PEN As Integer = &H40
        Private Const TOUCHINPUTMASKF_TIMEFROMSYSTEM As Integer = &H1
        Private Const TOUCHINPUTMASKF_EXTRAINFO As Integer = &H2
        Private Const TOUCHINPUTMASKF_CONTACTAREA As Integer = &H4
     
        ' Gesture IDs 
        Private Const GID_BEGIN As Integer = 1
        Private Const GID_END As Integer = 2
        Private Const GID_ZOOM As Integer = 3
        Private Const GID_PAN As Integer = 4
        Private Const GID_ROTATE As Integer = 5
        Private Const GID_TWOFINGERTAP As Integer = 6
        Private Const GID_PRESSANDTAP As Integer = 7
     
        <StructLayout(LayoutKind.Sequential)>
        Public Structure TOUCHINPUT
            Public x As Integer
            Public y As Integer
            Public hSource As System.IntPtr
            Public dwID As Integer
            Public dwFlags As Integer
            Public dwMask As Integer
            Public dwTime As Integer
            Public dwExtraInfo As System.IntPtr
            Public cxContact As Integer
            Public cyContact As Integer
        End Structure
        <StructLayout(LayoutKind.Sequential)>
        Public Structure POINTS
            Public x As Short
            Public y As Short
        End Structure
        <StructLayout(LayoutKind.Sequential)>
        Public Structure GESTUREINFO
            Public cbSize As Integer
            Public dwFlags As Integer
            Public dwID As Integer
            Public hwndTarget As IntPtr
            <MarshalAs(UnmanagedType.Struct)>
            Friend ptsLocation As POINTS
            Public dwInstanceID As Integer
            Public dwSequenceID As Integer
            Public ullArguments As Int64
            Public cbExtraArgs As Integer
        End Structure
     
        Declare Function RegisterTouchWindow Lib "user32.dll" (ByVal hWnd As System.IntPtr, ByVal ulFlags As UInteger) As Boolean
        Declare Function UnregisterTouchWindow Lib "user32.dll" (ByVal hWnd As System.IntPtr) As Boolean
        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
        Declare Sub CloseTouchInputHandle Lib "user32" (ByVal lParam As System.IntPtr)
     
        Declare Function GetGestureInfo Lib "user32.dll" (ByVal hGestureInfo As IntPtr, ByRef pGestureInfo As GESTUREINFO) As <MarshalAs(UnmanagedType.Bool)> Boolean
     
        Private touchInputSize As Integer
        Dim _gestureInfoSize As Integer
     
        <PermissionSet(SecurityAction.Demand, Name:="FullTrust")>
        Protected Overrides Sub WndProc(ByRef m As Message)
            Dim handled As Boolean
     
            Select Case m.Msg
                Case WM_TOUCH
                    'Infos.TB_infos.AppendText("Touché" & vbCrLf)
                    handled = DecodeTouch(m)
                Case WM_GESTURE ', WM_GESTURENOTIFY
                    handled = DecodeGesture(m)
                Case WM_PARENTNOTIFY
                    Infos.TB_infos.AppendText("WM_PARENTNOTIFY: " & m.Msg.ToString("000") & " - " & Hex(m.Msg) & vbCrLf)
                    handled = False
                Case Else
                    handled = False
            End Select
     
            MyBase.WndProc(m)
     
            If handled Then
                m.Result = New System.IntPtr(1)
            End If
        End Sub
     
        Dim pointts(10) As Point
     
        Private Function DecodeTouch(ByRef m As Message) As Boolean
            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
                Return False
                Exit Function
            End If
     
            For i As Integer = 0 To inputCount - 1
                Dim ti As TOUCHINPUT = inputs(i)
                If (ti.dwFlags And TOUCHEVENTF_DOWN) <> 0 Then
                    Dim pt As Point = PointToClient(New Point(ti.x / 100, ti.y / 100))
                    Infos.TB_infos.AppendText("Down" & i.ToString & ": " & pt.X.ToString & " x " & pt.Y.ToString & vbCrLf)
                    pointts(i) = pt
                ElseIf (ti.dwFlags And TOUCHEVENTF_UP) <> 0 Then
                    Dim pt As Point = PointToClient(New Point(ti.x / 100, ti.y / 100))
                    Infos.TB_infos.AppendText("Up" & i.ToString & ": " & pt.X.ToString & " x " & pt.Y.ToString & vbCrLf)
                    pointts(i) = pt
                ElseIf (ti.dwFlags And TOUCHEVENTF_MOVE) <> 0 Then
                    Dim pt As Point = PointToClient(New Point(ti.x / 100, ti.y / 100))
                    If pt <> pointts(i) Then
                        Infos.TB_infos.AppendText("Move" & i.ToString & ": " & pt.X.ToString & " x " & pt.Y.ToString & vbCrLf)
                    End If
                    pointts(i) = pt
                End If
            Next
            CloseTouchInputHandle(m.LParam)
            Return True
        End Function
     
        Private Function DecodeGesture(ByRef m As Message) As Boolean
            Dim gi As GESTUREINFO
     
            Try
                gi = New GESTUREINFO()
            Catch excep As Exception
                Debug.Print("Could not allocate resources to decode gesture")
                Debug.Print(excep.ToString())
                Return False
            End Try
     
            gi.cbSize = _gestureInfoSize
     
            If Not GetGestureInfo(m.LParam, gi) Then
                Return False
            Else
                Dim cible As IntPtr = gi.hwndTarget
                Dim txt As String = "WM_GESTURE sur "
                Select Case cible
                    Case Me.Handle
                        txt += "Form1: "
                    Case PictureBox1.Handle
                        txt += "PictureBox1: "
                    Case Panel1.Handle
                        txt += "Panel1: "
                End Select
                Select Case gi.dwID
                    Case GID_ZOOM
                        txt += "GID_ZOOM"
                    Case GID_TWOFINGERTAP
                        txt += "GID_TWOFINGERTAP"
                    Case GID_PRESSANDTAP
                        txt += "GID_PRESSANDTAP"
                End Select
                Infos.TB_infos.AppendText(txt & vbCrLf)
                Return True
            End If
        End Function
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            touchInputSize = Marshal.SizeOf(New TOUCHINPUT())
            Infos.Show()
            _gestureInfoSize = Marshal.SizeOf(New GESTUREINFO())
        End Sub
     
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Not RegisterTouchWindow(Me.Handle, 0) Then
                Infos.TB_infos.AppendText("ERROR: Could not register window for multi-touch")
            End If
        End Sub
     
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            UnregisterTouchWindow(Me.Handle)
        End Sub
     
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            If Not RegisterTouchWindow(Panel1.Handle, 0) Then
                Infos.TB_infos.AppendText("ERROR: Could not register panel for multi-touch")
            End If
        End Sub
     
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            If Not RegisterTouchWindow(PictureBox1.Handle, 0) Then
                Infos.TB_infos.AppendText("ERROR: Could not register picturebox for multi-touch")
            End If
        End Sub
     
        Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
            UnregisterTouchWindow(Panel1.Handle)
        End Sub
     
        Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
            UnregisterTouchWindow(PictureBox1.Handle)
        End Sub
    End Class
    J'ai ajouté un panel à gauche et un picturebox à droite et 6 boutons pour abonner ou désabonner les 3 éléments (form, picturebox, panel)

    Si aucun abonnement : les gestes de base (Zoom, tape a deux doigts, press and tap) sont bien rendus sur le control sous-jacent quel qu'il soit.

    Si on abonne la form (Me), les gestes sont ignorés et remplacés par WM_TOUCH.

    Si on abonne le picturebox ou le panel, les gestes sont aussi ignorés mais pas de WM_TOUCH.

    J'ai un peu cherché sur internet : il y a relativement peu de question là dessus et malheureusement jamais de réponse :
    https://www.vbarchiv.net/forum/read....12&i=75412&v=f

    On doit rater quelque chose mais quoi ?

    Edit: En fait, après bonne traduction du lien que j'ai mis, il semble que l'auteur du post ait trouvé comment faire "J'ai maintenant essayé le sous-classement. Ici aussi, la valeur de retour est toujours 1, mais avec cela, je reçois également mon message WM_TOUCH de la PictureBox.".
    Bon, plus qu'a étudier le code qu'il a joint. Peut être demain.
    Fichiers attachés Fichiers attachés

  13. #13
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 18
    Points
    18
    Par défaut
    Je vais creuser aussi de mon coté !
    Merci encore pour les tests ;-)

  14. #14
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 18
    Points
    18
    Par défaut
    Salut salut,

    tiens regarde ça marche :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  15. #15
    Membre habitué
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cher (Centre)

    Informations forums :
    Inscription : Mars 2011
    Messages : 105
    Points : 153
    Points
    153
    Par défaut
    Excellent
    Je vais me faire un petit programme qui regroupe tout ça (abonnement, désabonnement pour alternance WM_TOUCH / WM_GESTURE etc...)
    Pour l'instant c'est frais mais si le besoin s'en fait sentir dans 6 mois...

  16. #16
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 18
    Points
    18
    Par défaut
    Yes c'est une bonne nouvelle !!

    Je suis en train de regarder si je peux savoir si je suis en mode tactile ou non et ça sera parfait !

    Merci et bonne journée ;-)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Winforms / Windows 8 - Problème d’interaction MultiTouch
    Par Sometimes dans le forum Développement Windows
    Réponses: 0
    Dernier message: 11/12/2013, 15h12
  2. [VS.NET] [WinForms] [VB.NET] Créer un installeur
    Par Fruity dans le forum Windows Forms
    Réponses: 3
    Dernier message: 21/05/2008, 15h50
  3. [C#] [WinForms] Ascenceur du DataGrid !!!
    Par vandeyy dans le forum Windows Forms
    Réponses: 9
    Dernier message: 21/09/2004, 16h15
  4. [VB.NET] [WinForms] Emdebed Ressource !
    Par maitrebn dans le forum Windows Forms
    Réponses: 2
    Dernier message: 13/07/2004, 11h46
  5. [VB.NET] [Winform] DataGrid Excel et CheckBox
    Par mic56 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 24/06/2004, 15h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo