Example #1
0
        private static void WndProc(Window window, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == NativeMethods.WM_TOUCH)
            {
                var inputCount = wParam.ToInt32() & 0xffff;
                var inputs     = new NativeMethods.TOUCHINPUT[inputCount];

                if (NativeMethods.GetTouchInputInfo(lParam, inputCount, inputs, NativeMethods.TouchInputSize))
                {
                    for (int i = 0; i < inputCount; i++)
                    {
                        var input = inputs[i];
                        // 下面没有处理 DPI 问题
                        // 相对的是没有处理 DPI 的屏幕坐标
                        // 因为是 物理屏幕坐标的像素的百分之一表示,需要除 100 计算像素
                        var position = new Point(input.X / 100.0, input.Y / 100.0);
                        var size     = new Size(input.CxContact / 100.0, input.CyContact / 100.0);

                        if (!_devices.TryGetValue(input.DwID, out var device))
                        {
                            device = new MessageTouchDevice(input.DwID, window);
                            _devices.Add(input.DwID, device);
                        }

                        if (!device.IsActive && input.DwFlags.HasFlag(NativeMethods.TOUCHEVENTF.TOUCHEVENTF_DOWN))
                        {
                            device.Position = position;
                            device.Size     = size;
                            device.Down();
                        }
                        else if (device.IsActive && input.DwFlags.HasFlag(NativeMethods.TOUCHEVENTF.TOUCHEVENTF_UP))
                        {
                            device.Position = position;
                            device.Size     = size;
                            device.Up();
                        }
                        else if (device.IsActive && input.DwFlags.HasFlag(NativeMethods.TOUCHEVENTF.TOUCHEVENTF_MOVE))
                        {
                            device.Position = position;
                            device.Size     = size;
                            device.Move();
                        }
                    }
                }

                NativeMethods.CloseTouchInputHandle(lParam);
                handled = true;
            }
        }
Example #2
0
 private void MainWindow_SourceInitialized(object sender, EventArgs e)
 {
     MessageTouchDevice.UseMessageTouch(this);
 }