www.JosXP.com, Joomla Professionals

Capturing Mouse Enter (MouseOver) and Mouse Leave (MouseOut) events: 


Category:
System
API:  SetCapture | GetCapture | ReleaseCapture

How to capture the MouseEnter and MouseLeave?

Typical example shows you how to capture the MouseEnter (or MouseOver) and MouseLeave (or MouseOut) events.

Look at this code:

Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   If ((X < 0) Or (X > UserControl.Width) Or (Y < 0) Or (Y > UserControl.Height)) Then
   'Mouse Leave (The mouse rolls out the control)
      RaiseEvent OnMouseLeave
      Call ReleaseCapture
   ElseIf GetCapture <> UserControl.hWnd Then
   'Mouse Enter (The mouse rolls over the control
   'and GetCapture <> UserControl.hWnd which means first time mouse move)

      RaiseEvent OnMouseEnter
      Call SetCapture(UserControl.hWnd)
   Else
   'Mouse Move
      RaiseEvent OnMouseMove(Button, Shift, X, Y)
   End If
End Sub

The SetCapture function sets the mouse capture to the specified window belonging to the current thread. Once a window has captured the mouse, all mouse input is directed to that window, even if the mouse rolls out the window.

The ReleaseCapture function releases the mouse capture from a window in the current thread and restores normal mouse input processing.

The GetCapture function returns the window handle which captures the mouse.




Trick Never Seen Before!