/// <summary> /// 触摸消息转WPF事件 /// 此方案只支持Touch,没有Stylus事件。同时Touch与Mouse事件被独立开了。--此方案有缺陷,但能勉强使用。TODO 模拟Stylus事件触发 /// </summary> /// <param name="window"></param> /// <param name="input"></param> private static void FakeTouchInputToWindow(Window window, TouchNativeMethods.TOUCHINPUT input) { // 相对的是没有处理 DPI 的屏幕坐标 // 因为是 物理屏幕坐标的像素的百分之一表示,需要除 100 计算像素 var screenLocation = new Point(input.X / 100.0, input.Y / 100.0); var wpfLocation = TransformToWpfPoint(screenLocation, window); var sizeInScreen = new Size(input.CxContact / 100.0, input.CyContact / 100.0); var wpfSize = TransformToWpfSize(sizeInScreen, window); //获取触摸设备信息 var device = MessageTouchDeviceHelper.GetDevice(window, input.DwID); if (!device.IsActive && input.DwFlags.HasFlag(TouchNativeMethods.TOUCHEVENTF.TOUCHEVENTF_DOWN)) { device.Position = wpfLocation; device.Size = wpfSize; device.Down(); } else if (device.IsActive && input.DwFlags.HasFlag(TouchNativeMethods.TOUCHEVENTF.TOUCHEVENTF_MOVE)) { device.Position = wpfLocation; device.Size = wpfSize; device.Move(); } else if (device.IsActive && input.DwFlags.HasFlag(TouchNativeMethods.TOUCHEVENTF.TOUCHEVENTF_UP)) { device.Position = wpfLocation; device.Size = wpfSize; device.Up(); MessageTouchDeviceHelper.Remove(device); } }
private void Window_Closed(object sender, EventArgs e) { MessageTouchDeviceHelper.Remove(this); }