お世話になります。
以下の環境で、Windowsタッチの調査をしております。
フォームを押したときのタッチイベントは取得できたのですが、
フォームに張り付けた、コントロールのタッチイベントが取得できません。
そもそも、取得できないのでしょうか?
OS:Windows10(タブレット)
言語:C#
フレームワーク:.NET Framework4
以下、サンプルコードです。
タッチした場合に、WM_TOUCHイベントを受信したカウンタを表示するようにしています。
C#
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Windows.Forms; 9using System.Runtime.InteropServices; 10 11 12namespace WindowsTouch01 13{ 14 15 16 public partial class Form1 : Form 17 { 18 19 20 [DllImport("user32.dll")] 21 [return: MarshalAs(UnmanagedType.Bool)] 22 public static extern bool RegisterTouchWindow(IntPtr hWnd, uint ulFlags); 23 [DllImport("user32.dll")] 24 [return: MarshalAs(UnmanagedType.Bool)] 25 private static extern bool GetTouchInputInfo(IntPtr hTouchInput, int cInputs, [In, Out] TOUCHINPUT[] pInputs, int cbSize); 26 27 private int _count = 0; 28 private int _count2 = 0; 29 30 private struct TOUCHINPUT 31 { 32 public int x; 33 public int y; 34 public System.IntPtr hSource; 35 public int dwID; 36 public int dwFlags; 37 public int dwMask; 38 public int dwTime; 39 public System.IntPtr dwExtraInfo; 40 public int cxContact; 41 public int cyContact; 42 } 43 private const int WM_TOUCH = 0x0240; 44 public Form1() 45 { 46 InitializeComponent(); 47 } 48 49 private void Form1_Load(object sender, EventArgs e) 50 { 51 bool result = RegisterTouchWindow(this.Handle, 0); 52 Console.WriteLine(result); 53 result = RegisterTouchWindow(button1.Handle, 0); 54 Console.WriteLine(result); 55 result = RegisterTouchWindow(panel1.Handle, 0); 56 Console.WriteLine(result); 57 58 _count = 0; 59 _count2 = 0; 60 label1.Text = String.Format("(1) WM_TOUCH {0}", _count); 61 label2.Text = String.Format("(1) ON CLICKED {0}", _count2); 62 63 64 } 65 66 protected override void WndProc(ref Message m) 67 { 68 switch (m.Msg) 69 { 70 case WM_TOUCH: 71 int inputCount = (int)(m.WParam.ToInt32() & 0xFFFF); 72 TOUCHINPUT[] inputs = new TOUCHINPUT[inputCount]; 73 bool result = GetTouchInputInfo(m.LParam, inputCount, inputs, Marshal.SizeOf(inputs[0])); 74 75 76 label1.Text = String.Format("(1) WM_TOUCH {0}", _count); 77 _count++; 78 break; 79 default: 80 break; 81 } 82 base.WndProc(ref m); 83 } 84 85 private void button1_Click(object sender, EventArgs e) 86 { 87 label2.Text = String.Format("(1) ON CLICKED {0}", _count2); 88 _count2++; 89 } 90 } 91} 92

回答2件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2017/05/31 09:06
2017/05/31 09:09
2017/05/31 09:49