- 題名: APIのGetTouchInputInfoについて
- 日時: 2014/01/23 16:41:54
- ID: 32095
- この記事の返信元:
- (なし)
- この記事への返信:
- [32096] Re[1]: APIのGetTouchInputInfoについて 2014/01/23 17:25:14
- ツリーを表示
■No32096に返信(aさんの記事)
> ■No32095に返信(まりもんさんの記事)
>> Dim x As Long
>> Dim y As Long
> >
> 32bitと64bitでサイズが違っているんじゃないかな。
> VB.NETのLong->64bit, サイト上の構造体の定義は32bitを表しているのだと思う。
> 外してたらごめんね。
定義を
<StructLayout(LayoutKind.Sequential)> _
Structure TOUCHINPUT
Dim x As Int32
Dim y As Int32
Dim hSource As IntPtr
Dim dwID As UInt32
Dim dwFlags As UInt32
Dim dwMask As UInt32
Dim dwTime As UInt32
Dim dwExtraInfo As IntPtr
Dim cxContact As UInt32
Dim cyContact As UInt32
End Structure
に変更したところ、正常な値と思える状態になりました。
まだ検証が必要ですが、とりあえず解決とします。
ありがとうございました。
分類:[.NET]
Windows7にて、タッチパネルのイベントの取得を作成しています。 WndProcで、WM_TOUCHは取れるようになったのですが、 GetTouchInputInfoにて、詳細情報を取得すると、構造体の中身が正常だとは思えない 値になっています。 下記ソースで言えば、inputs(i).dwFlagsが常に0になってしまいます。 どのようにすれば、正しい情報が取得できるようになるのでしょうか? ---------------------------以下ソース--------------------------- Imports System.Runtime.InteropServices Public Class Form1 Private Declare Function RegisterTouchWindow Lib "user32.dll" _ (ByVal hWnd As IntPtr, ByVal ulFlags As UInt32) As Boolean Private Declare Function UnregisterTouchWindow Lib "user32.dll" _ (ByVal hWnd As IntPtr) As Boolean Private Declare Function GetTouchInputInfo Lib "user32.dll" _ (ByVal hTouchInput As IntPtr, ByVal cInputs As UInt32, _ ByVal pInputs As IntPtr, ByVal cbSize As Integer) As Boolean Private Declare Function CloseTouchInputHandle Lib "user32.dll" _ (ByVal hTouchInput As IntPtr) As Boolean <StructLayout(LayoutKind.Sequential)> _ Structure TOUCHINPUT Dim x As Long Dim y As Long Dim hSource As UInt32 Dim dwID As UInt32 Dim dwFlags As UInt32 Dim dwMask As UInt32 Dim dwTime As UInt32 Dim dwExtraInfo As UInt32 Dim cxContact As UInt32 Dim cyContact As UInt32 End Structure Private Const WM_TOUCH = &H240 Private Const TOUCHEVENTF_DOWN = &H2 Private Const TOUCHEVENTF_UP = &H4 Private Const TOUCHEVENTF_INRANGE = &H8 Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs) MyBase.OnHandleCreated(e) RegisterTouchWindow(Me.Handle, 0) End Sub Protected Overrides Sub OnHandleDestroyed(ByVal e As System.EventArgs) MyBase.OnHandleDestroyed(e) UnregisterTouchWindow(Me.Handle) End Sub Protected Overrides Sub WndProc(ByRef m As Message) If m.Msg = WM_TOUCH Then DecodeTouch(m.LParam, m.WParam) Else MyBase.WndProc(m) End If End Sub Private Sub DecodeTouch(ByVal lParam As IntPtr, ByVal wParam As IntPtr) Dim cInputs As UInt32 = wParam.ToInt32 And &HFFFF Dim inputs(cInputs) As TOUCHINPUT Dim gch As GCHandle = GCHandle.Alloc(inputs, GCHandleType.Pinned) Dim b As IntPtr = gch.AddrOfPinnedObject().ToInt32 If GetTouchInputInfo(lParam, cInputs, b, 48) Then For i = 0 To cInputs - 1 Trace.WriteLine(inputs(i).dwFlags) If inputs(i).dwFlags And TOUCHEVENTF_DOWN Then Trace.WriteLine("DOWN") End If If inputs(i).dwFlags And TOUCHEVENTF_UP Then Trace.WriteLine("UP") End If Next Else Trace.WriteLine(System.Runtime.InteropServices.Marshal.GetLastWin32Error()) End If CloseTouchInputHandle(lParam) gch.Free() End Sub End Class GetTouchInputInfo 関数 http://msdn.microsoft.com/ja-jp/library/windows/desktop/dd371582%28v=vs.85%29.aspx TOUCHINPUT構造体 http://msdn.microsoft.com/ja-jp/library/windows/desktop/dd317334%28v=vs.85%29.aspx