Пример #1
0
 /// <summary>
 /// Create new touch event argument instance
 /// </summary>
 /// <param name="hWndWrapper">The target control</param>
 /// <param name="touchInput">one of the inner touch input in the message</param>
 internal TouchEventArgs(IHwndWrapper hWndWrapper, float dpiX, float dpiY, ref TOUCHINPUT touchInput)
 {
     _hWndWrapper = hWndWrapper;
     _dpiXFactor = 96F / dpiX;
     _dpiYFactor = 96F / dpiY;
     DecodeTouch(ref touchInput);
 }
Пример #2
0
 /// <summary>
 /// Create new touch event argument instance
 /// </summary>
 /// <param name="hWndWrapper">The target control</param>
 /// <param name="touchInput">one of the inner touch input in the message</param>
 internal TouchEventArgs(IHwndWrapper hWndWrapper, float dpiX, float dpiY, ref TOUCHINPUT touchInput)
 {
     //need to change according to device
     _hWndWrapper = hWndWrapper;
     _dpiXFactor = dpiX / dpiX;//120F / dpiX;
     _dpiYFactor = dpiY / dpiY;//120F / dpiY;
     DecodeTouch(ref touchInput);
 }
Пример #3
0
        /// <summary>
        /// Decode the message and create a collection of event arguments
        /// </summary>
        /// <remarks>
        /// One Windows message can result a group of events
        /// </remarks>
        /// <returns>An enumerator of thr resuting events</returns>
        /// <param name="hWnd">the WndProc hWnd</param>
        /// <param name="msg">the WndProc msg</param>
        /// <param name="wParam">the WndProc wParam</param>
        /// <param name="lParam">the WndProc lParam</param>
        private IEnumerable<TouchEventArgs> DecodeMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, float dpiX, float dpiY)
        {
            // More than one touchinput may be associated with a touch message,
            // so an array is needed to get all event information.
            int inputCount = User32.LoWord(wParam.ToInt32()); // Number of touch inputs, actual per-contact messages

            TOUCHINPUT[] inputs; // Array of TOUCHINPUT structures
            inputs = new TOUCHINPUT[inputCount]; // Allocate the storage for the parameters of the per-contact messages
            try
            {
                // Unpack message parameters into the array of TOUCHINPUT structures, each
                // representing a message for one single contact.
                if (!User32.GetTouchInputInfo(lParam, inputCount, inputs, Marshal.SizeOf(inputs[0])))
                {
                    // Get touch info failed.
                    throw new Exception("Error calling GetTouchInputInfo API");
                }

                // For each contact, dispatch the message to the appropriate message
                // handler.
                // Note that for WM_TOUCHDOWN you can get down & move notifications
                // and for WM_TOUCHUP you can get up & move notifications
                // WM_TOUCHMOVE will only contain move notifications
                // and up & down notifications will never come in the same message
                for (int i = 0; i < inputCount; i++)
                {
                    TouchEventArgs touchEventArgs = new TouchEventArgs(HWndWrapper, dpiX, dpiY, ref inputs[i]);
                    yield return touchEventArgs;
                }
            }
            finally
            {
                User32.CloseTouchInputHandle(lParam);
            }
        }
Пример #4
0
        // Decodes and handles WM_TOUCH* messages.
        private void DecodeTouch(ref TOUCHINPUT touchInput)
        {
            // TOUCHINFO point coordinates and contact size is in 1/100 of a pixel; convert it to pixels.
            // Also convert screen to client coordinates.
            if ( (touchInput.dwMask & User32.TOUCHINPUTMASKF_CONTACTAREA) != 0)
                ContactSize = new Size(AdjustDpiX(touchInput.cyContact / 100), AdjustDpiY(touchInput.cyContact / 100));

            Id = touchInput.dwID;

            Point p = new Point(touchInput.x / 100, touchInput.y / 100);//_hWndWrapper.PointToClient(new Point(touchInput.x / 100, touchInput.y / 100));//
            //Debug.WriteLine("sf" + p.ToString());
            Location = new Point(AdjustDpiX(p.X), AdjustDpiY(p.Y));

            Time = touchInput.dwTime;
            TimeSpan ellapse = TimeSpan.FromMilliseconds(Environment.TickCount - touchInput.dwTime);
            AbsoluteTime = DateTime.Now - ellapse;

            Mask = touchInput.dwMask;
            Flags = touchInput.dwFlags;
        }