/// <summary> /// The Windows message interception for gesture events handling /// </summary> /// <param name="hWnd">WndProc hWnd</param> /// <param name="msg">WndProc msg</param> /// <param name="wParam">WndProc wParam</param> /// <param name="lParam">WndProc lParam</param> /// <returns>WndProc return</returns> public override uint WindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) { //We care only for gesture events if (msg != User32.WM_GESTURE) { return(0); } GESTUREINFO gestureInfo = new GESTUREINFO { cbSize = (uint)Marshal.SizeOf(typeof(GESTUREINFO)) }; bool result = User32.GetGestureInfo(lParam, ref gestureInfo); if (!result) { throw new Exception("Cannot get gesture information"); } //Decode the gesture info and get the message event argument GestureEventArgs eventArgs = new GestureEventArgs(this, ref gestureInfo); try { //Fire the event using the event map _eventMap[MapWM2EventId(gestureInfo.dwID, gestureInfo.dwFlags)].Invoke(this, eventArgs); } catch (ArgumentOutOfRangeException) //In case future releases will introduce new event values { } //Keep the last message for relative calculations LastEvent = eventArgs; //Keep the first message for relative calculations if (eventArgs.IsBegin) { LastBeginEvent = eventArgs; } User32.CloseGestureInfoHandle(lParam); return(1); }