public void DecodeTouch(ref Message m)
{
if (m.Msg != Win32.WM_TOUCH)
{
// WM_TOUCHではない。
return;
}
int touchInputSize = Marshal.SizeOf(inputBuffer[0]);
int inputCount = (ushort)m.WParam.ToInt32();
if (inputCount > inputBuffer.Length)
{
Win32.CloseTouchInputHandle(m.LParam);
m.Result = IntPtr.Zero;
return;
}
if (!Win32.GetTouchInputInfo(m.LParam, inputCount, inputBuffer, touchInputSize))
{
Win32.CloseTouchInputHandle(m.LParam);
m.Result = IntPtr.Zero;
Debug.Print("Error on GetTouchInputInfo.");
return;
}
for (int i = 0; i < inputCount; i++)
{
TouchEvent e = inputBuffer[i];
Win32.POINT p = new Win32.POINT() { X = e.X / 100, Y = e.Y / 100 };
Win32.ScreenToClient(m.HWnd, ref p);
e.X = p.X;
e.Y = p.Y;
e.Width = e.HasContact ? e.Width / 100 : 0;
e.Height = e.HasContact ? e.Height / 100 : 0;
//Debug.Print("ID{4}-{7} x{0} y{1} w{2} h{3} P{5} R{6}",
// e.X, e.Y, e.Width, e.Height, e.ID,
// e.Primary, e.InRange,
// (e.Down ? "D" : e.Up ? "U" : "M")
// );
if (TouchEvent != null)
{
TouchEvent(this, e);
}
}
Win32.CloseTouchInputHandle(m.LParam);
return;
}