Example #1
0
		/// <summary>
		/// Resets Hoover timer for specified control.
		/// </summary>
		public static void ResetHover(System.Windows.Forms.Control c)
		{
			if (c==null || !c.IsHandleCreated)
				return;
			
			// We need to reset hover thing since it is fired only first time mouse hovers inside the window and we need it for each of our items
			TRACKMOUSEEVENT tme = new TRACKMOUSEEVENT();
			tme.dwFlags = TME_QUERY;
			tme.hwndTrack = c.Handle;
			tme.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(tme);
			TrackMouseEvent(ref tme);
			tme.dwFlags = tme.dwFlags | TME_HOVER;
			TrackMouseEvent(ref tme);
		}
 private void trackMouse(IntPtr Hwnd)
 {
     TRACKMOUSEEVENT tM = new TRACKMOUSEEVENT();
     tM.cbSize = (uint)Marshal.SizeOf(tM);
     tM.dwFlags = TRACKMOUSEEVENT_FLAGS.TME_LEAVE;
     tM.hwndTrack = Hwnd;
     TrackMouseEvent(ref tM);
 }
 public static extern int TrackMouseEvent(ref TRACKMOUSEEVENT eventTrack);
 public static extern bool TrackMouseEvent(TRACKMOUSEEVENT tme);
Example #5
0
 internal void ResetHoverTracking(IntPtr handle)
 {
     if (trackMouseEvent == null) {
         trackMouseEvent = new TRACKMOUSEEVENT();
         trackMouseEvent.dwFlags = TME_HOVER;
         trackMouseEvent.hwndTrack = handle;
     }
     TrackMouseEvent(trackMouseEvent);
 }
Example #6
0
		private extern static bool Win32TrackMouseEvent(ref TRACKMOUSEEVENT tme);
Example #7
0
		internal override void ResetMouseHover(IntPtr handle) {
			TRACKMOUSEEVENT	tme;

			tme = new TRACKMOUSEEVENT();
			tme.size = Marshal.SizeOf(tme);
			tme.hWnd = handle;
			tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
			Win32TrackMouseEvent(ref tme);
		}
Example #8
0
        protected override void WndProc(ref Message m)
        {
            try
            {
                int code = m.Msg;
                DualParameter wParam = (DualParameter)m.WParam;
                DualParameter lParam = (DualParameter)m.LParam;
                switch (m.Msg)
                {
                    case WM_CLOSE:
                    {
                        if(OnClose != null) OnClose();
                        return;
                    }
                    case WM_SIZE:
                    {
                        Size = new Point2D(lParam.LowWord, lParam.HighWord);
                        if(OnResize != null) OnResize(Size);
                        break;
                    }
                    case WM_PAINT:
                    {
                        PaintData data;
                        IntPtr screenDC = BeginPaint(Handle, out data);
                        WinAPIUtils.Assert(screenDC != IntPtr.Zero);

                        //blit display buffer to screen
                        Image buffer = BufferStrategy.GetDisplayBuffer().Image;
                        bool success = BitBlt(screenDC, 0, 0, buffer.Width, buffer.Height, buffer.GetDeviceContext(), 0, 0, SRCCOPY);
                        WinAPIUtils.Assert(success);

                        EndPaint(Handle, ref data);
                        return;
                    }
                    case WM_SETFOCUS:
                    {
                        IsFocused = true;
                        break;
                    }
                    case WM_KILLFOCUS:
                    {
                        IsFocused = false;
                        break;
                    }
                    case WM_MOUSEMOVE:
                    {
                        //get move info
                        Point2D mouseCoords = (Point2D)lParam;
                        Point2D delta = mouseCoords - PrevMouseCoords;
                        //if mouse was previously outside window
                        if(!IsMouseInWindow)
                        {
                            IsMouseInWindow = true;
                            if(OnMouseEnter != null) OnMouseEnter();
                            //suppress inaccurate delta value
                            delta = new Point2D(0, 0);
                            //start tracking mouse so we recieve WM_MOUSELEAVE
                            TRACKMOUSEEVENT eventTrack = new TRACKMOUSEEVENT(Handle);
                            bool success = TrackMouseEvent(ref eventTrack);
                            WinAPIUtils.Assert(success);
                        }

                        //call event
                        if(OnMouseMove != null)
                        {
                            OnMouseMove(mouseCoords, delta);
                            PrevMouseCoords = mouseCoords;
                            //consume
                            return;
                        }else
                        {
                            PrevMouseCoords = mouseCoords;
                        }
                        break;
                    }
                    case WM_MOUSELEAVE:
                    {
                        IsMouseInWindow = false;
                        if(OnMouseExit != null) OnMouseExit();
                        break;
                    }
                    case WM_LBUTTONDOWN:
                    {
                        if(OnMousePress != null)
                        {
                            OnMousePress(MouseButton.LEFT);
                            //consume
                            return;
                        }
                        break;
                    }
                    case WM_LBUTTONUP:
                    {
                        if(OnMouseRelease != null)
                        {
                            OnMouseRelease(MouseButton.LEFT);
                            //consume
                            return;
                        }
                        break;
                    }
                    case WM_RBUTTONDOWN:
                    {
                        if(OnMousePress != null)
                        {
                            OnMousePress(MouseButton.RIGHT);
                            //consume
                            return;
                        }
                        break;
                    }
                    case WM_RBUTTONUP:
                    {
                        if(OnMouseRelease != null)
                        {
                            OnMouseRelease(MouseButton.RIGHT);
                            //consume
                            return;
                        }
                        break;
                    }
                    case WM_MBUTTONDOWN:
                    {
                        if(OnMousePress != null)
                        {
                            OnMousePress(MouseButton.MIDDLE);
                            //consume
                            return;
                        }
                        break;
                    }
                    case WM_MBUTTONUP:
                    {
                        if(OnMouseRelease != null)
                        {
                            OnMouseRelease(MouseButton.MIDDLE);
                            //consume
                            return;
                        }
                        break;
                    }
                    case WM_XBUTTONDOWN:
                    {
                        if(OnMousePress != null)
                        {
                            MouseButton button = (wParam.HighWord == 0x0001 ? MouseButton.EXTRA_1 : MouseButton.EXTRA_2);
                            OnMousePress(button);
                            //consume
                            return;
                        }
                        break;
                    }
                    case WM_XBUTTONUP:
                    {
                        if(OnMouseRelease != null)
                        {
                            MouseButton button = (wParam.HighWord == 0x0001 ? MouseButton.EXTRA_1 : MouseButton.EXTRA_2);
                            OnMouseRelease(button);
                            //consume
                            return;
                        }
                        break;
                    }
                    case WM_MOUSEWHEEL:
                    {
                        if(OnMouseWheel != null)
                        {
                            int delta = (wParam.HighWord / WHEEL_DELTA);
                            OnMouseWheel(delta);
                            //consume
                            return;
                        }
                        break;
                    }
                    case WM_KEYDOWN:
                    case WM_SYSKEYDOWN:
                    {
                        if(OnKeyPress != null)
                        {
                            //only post event if not a repeat
                            //aka previous state up
                            if((lParam.Number & 0x40000000) == 0)
                            {
                                KeyboardButton button = (KeyboardButton)wParam.Number;
                                OnKeyPress(button);
                                //consume
                                return;
                            }
                        }
                        break;
                    }
                    case WM_KEYUP:
                    case WM_SYSKEYUP:
                    {
                        if(OnKeyRelease != null)
                        {
                            //only post event if not a repeat
                            //aka previous state down
                            if((lParam.Number & 0x40000000) != 0)
                            {
                                KeyboardButton button = (KeyboardButton)wParam.Number;
                                OnKeyRelease(button);
                                //consume
                                return;
                            }
                        }
                        break;
                    }
                    case WM_CHAR:
                    {
                        if(OnCharTyped != null)
                        {
                            char c = (char)wParam.Number;
                            bool repeat = ((lParam.Number & 0x40000000) != 0);
                            //ok if char events are repeats
                            OnCharTyped(c, repeat);
                            //consume
                            return;
                        }
                        break;
                    }
                }
            }catch(System.Threading.ThreadAbortException)
            {
                //do nothing, simply means we called Stop on the message thread
            }catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
            base.WndProc(ref m);
        }
Example #9
0
 public static bool TrackMouseEvent(TRACKMOUSEEVENT tme)
 {
     return(_TrackMouseEvent(tme));
 }
Example #10
0
 private static extern bool _TrackMouseEvent(TRACKMOUSEEVENT tme);
Example #11
0
 public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);
Example #12
0
 public static partial BOOL TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);
        /// <summary>
        /// Reset the mouse hover timer
        /// </summary>
        /// <param name="handle">The handle of the control in which to reset hover notification</param>
        internal static void ResetMouseHover(IntPtr handle)
        {
            TRACKMOUSEEVENT tme = new TRACKMOUSEEVENT();

            tme.hwndTrack = handle;
            tme.dwFlags = TME_HOVER;
            tme.dwHoverTime = HOVER_DEFAULT;
            tme.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(tme);

            TrackMouseEvent(ref tme);
        }
Example #14
0
 static extern int TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);
Example #15
0
 private static extern bool _TrackMouseEvent(TRACKMOUSEEVENT tme);
Example #16
0
 public static bool TrackMouseEvent(TRACKMOUSEEVENT tme)
 {
     return _TrackMouseEvent(tme);
 }
 public static extern int TrackMouseEvent(ref TRACKMOUSEEVENT eventTrack);
Example #18
0
 private static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT eventTrack);
 /// <summary>
 /// Private method to reset the mouse hover 
 /// </summary>
 /// /// <param name="box">picture box to reset the video frame</param>
 private void resetHover(PictureBox box)
 {
     TRACKMOUSEEVENT tme = new TRACKMOUSEEVENT(box.Handle);
     TrackMouseEvent(ref tme);
 }
Example #20
0
		private bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, bool blocking) {
			bool		result;

			msg.refobject = 0;
			if (RetrieveMessage(ref msg)) {
				return true;
			}

			if (blocking) {
				result = Win32GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
			} else {
				result = Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, (uint)PeekMessageFlags.PM_REMOVE);
				if (!result) {
					return false;
				}
			}

			// We need to fake WM_MOUSE_ENTER
			switch (msg.message) {
				case Msg.WM_LBUTTONDOWN: {
					mouse_state |= MouseButtons.Left;
					break;
				}

				case Msg.WM_MBUTTONDOWN: {
					mouse_state |= MouseButtons.Middle;
					break;
				}

				case Msg.WM_RBUTTONDOWN: {
					mouse_state |= MouseButtons.Right;
					break;
				}

				case Msg.WM_LBUTTONUP: {
					mouse_state &= ~MouseButtons.Left;
					break;
				}

				case Msg.WM_MBUTTONUP: {
					mouse_state &= ~MouseButtons.Middle;
					break;
				}

				case Msg.WM_RBUTTONUP: {
					mouse_state &= ~MouseButtons.Right;
					break;
				}

				case Msg.WM_ASYNC_MESSAGE: {
					XplatUIDriverSupport.ExecuteClientMessage((GCHandle)msg.lParam);
					break;
				}

				case Msg.WM_MOUSEMOVE: {
					if (msg.hwnd != prev_mouse_hwnd) {
						TRACKMOUSEEVENT	tme;

						mouse_state = Control.FromParamToMouseButtons ((int)msg.lParam.ToInt32());

						// The current message will be sent out next time around
						StoreMessage(ref msg);

						// This is the message we want to send at this point
						msg.message = Msg.WM_MOUSE_ENTER;

						prev_mouse_hwnd = msg.hwnd;

						tme = new TRACKMOUSEEVENT();
						tme.size = Marshal.SizeOf(tme);
						tme.hWnd = msg.hwnd;
						tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
						Win32TrackMouseEvent(ref tme);
						return result;
					}
					break;
				}

				case Msg.WM_NCMOUSEMOVE: {
					if (wm_nc_registered == null || !wm_nc_registered.Contains (msg.hwnd))
						break;

					mouse_state = Control.FromParamToMouseButtons ((int)msg.lParam.ToInt32 ());

					TRACKMOUSEEVENT tme;

					tme = new TRACKMOUSEEVENT ();
					tme.size = Marshal.SizeOf(tme);
					tme.hWnd = msg.hwnd;
					tme.dwFlags = (TMEFlags)wm_nc_registered[msg.hwnd];
					Win32TrackMouseEvent (ref tme);
					return result;
				}

				case Msg.WM_DROPFILES: {
					return Win32DnD.HandleWMDropFiles(ref msg);
				}

				case Msg.WM_MOUSELEAVE: {
					prev_mouse_hwnd = IntPtr.Zero;
					break;
				}

				case Msg.WM_TIMER: {
					Timer timer=(Timer)timer_list[(int)msg.wParam];

					if (timer != null) {
						timer.FireTick();
					}
					break;
				}
			}

			return result;
		}
Example #21
0
 protected override void WndProc(ref Message m)
 {
     const int WM_PAINT = 0xF;
     if (m.Msg == WM_MOUSEMOVE && !m_MouseTracking)
     {
         m_MouseTracking = true;
         TRACKMOUSEEVENT tme = new TRACKMOUSEEVENT();
         tme.dwFlags = TME_LEAVE;
         tme.cbSize = Marshal.SizeOf(tme);
         tme.hwndTrack = this.Handle;
         tme.dwHoverTime = 0;
         m_MouseTracking = TrackMouseEvent(ref tme);
     }
     else if (m.Msg == WM_MOUSELEAVE)
     {
         if (MouseLeave != null)
             MouseLeave(this, new EventArgs());
         m_MouseTracking = false;
     }
     else if (m.Msg == WM_PAINT)
     {
         base.WndProc(ref m);
         if (Paint != null)
         {
             using (Graphics g = Graphics.FromHwnd(m.HWnd))
                 Paint(this, new PaintEventArgs(g, Rectangle.Empty));
         }
         return;
     }
     base.WndProc(ref m);
 }
		public static extern bool TrackMouseEvent( ref TRACKMOUSEEVENT lpEventTrack );
Example #23
0
 internal void TrackMouseLeave(IntPtr handle)
 {
     if (trackMouseEvent == null)
     {
         trackMouseEvent = new TRACKMOUSEEVENT();
         trackMouseEvent.dwFlags = TME_LEAVE;
         trackMouseEvent.hwndTrack = handle;
         trackMouseEvent.dwHoverTime = 0;
     }
     if (!TrackMouseEvent(trackMouseEvent))
     {
         Debug.WriteLine("TrackMouseEvent failed, rc=" + Marshal.GetHRForLastWin32Error());
     }
 }