Handling mouse shift event

zhaozj2021-02-16  35

Windows offers the mouse to move the message is sometimes useful, but this event is not encapsulated in VB6. However, we can still use the subclassification technology to implement him. The following code is a simple example to handle Windows WM_MouseLeave messages, I demonstrated the situation when the mouse moved out of a Button.

1. Add a module to deal with subclassics:

Option expedition

'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ', 40STAR @ 163.com'Distribution: You can use this code completely freely, no matter any purpose 'program lies in communicating and learning', if you have any bug, please contact me '' '' '' '' '' '.' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'Private declare function sendmessage lib "user32" alias "sendMessagea" _ (Byval Hwnd as long, Byval WMSG As Long, _ Byval WPARAM AS Long, LPARAM AS STRING AS Long

Private Declare Function GetWindowLong Lib "user32" Alias ​​_ "GetWindowLongA" (ByVal hwnd As Long, _ ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias ​​_ "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex _ As Long , ByVal dwNewLong As Long) As Long Private Declare Function CallWindowProc Lib "user32" Alias ​​_ "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal _ hwnd As Long, ByVal Msg As Long, ByVal wParam As _ Long, ByVal lParam As Long) As Long const GWL_WndProc = (-4 &)

DIM PrevwndProc &

Private const wm_destroy = & h2

Public Declare Function TRACKMOUSEEVENT LIB "User32" (LPEVENTTRACK AS TRACKMOUSEEVENTTYPE) AS Long

Public const tme_cancel = & h80000000public const tme_hover = & h1 & public const same_leave = & h2 & public const same_nonclient = & h10 & public const tme_query = & h40000000

PRIVATE WM_MOUSELEAVE = & H2A3 & H2A3 &

Public Type TrackMouseEventType Cbsize As Long Dwflags As Long Hwndtrack As Long Dwhovertime As Longend Type

Public BTRACKING AS BooleandIM EVTTRACK AS TRACKMOLENTTYPE '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''

Private function subwndproc (Byval HWnd As Long, _ Byval WParam as long

'Handling the mouse to remove the message if msg = wm_mouseeleave dam1 btcking = false form1.print "The Mouse Left the form!" End if Subwndproc = CallWindowProc (prevwndproc, hwnd, msg, wparam, lparam) End Function

Public Sub INIT (HWND As Long) prevwndproc = setwindowlong (hwnd, gwl_wndproc, addressof subwndproc) End Sub

Public Sub Terminate (HWND As Long) Call SetWindowlong (HWND, GWL_WNDPROC, PrevwndProc) End Sub

'- Module end -'

2. The code that needs to be added in the form:

Option expedition

Private Sub Command1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single) If bTracking = False Then bTracking = True Dim ET As TRACKMOUSEEVENTTYPE 'initialize structure ET.cbSize = Len (ET) ET.hwndTrack = Command1.hwnd Et.dwflags = Tme_leave 'Start The Tracking TRACKMOUSEEVENT ETEND IFEND SUB

PRIVATE SUB FORM_LOAD () CALL INIT (Command1.hwnd) End Sub

Private Sub Form_Unload (Cancel AS Integer) Call Terminate (Command1.hwnd) End Sub

This routine is debugged in Win2000 VB6

转载请注明原文地址:https://www.9cbs.com/read-27500.html

New Post(0)