The following code is a way to use API to tell when a control no longer has the mouse over it. Any ideas how to find when a control gets the mouse over it using API?
Code:Public Const TME_CANCEL = &H80000000 Public Const TME_HOVER = &H1& Public Const TME_LEAVE = &H2& Public Const TME_NONCLIENT = &H10& Public Const TME_QUERY = &H40000000 Public Const WM_MOUSELEAVE = &H2A3& Public Type TRACKMOUSEEVENTTYPE cbSize As Long dwFlags As Long hwndTrack As Long dwHoverTime As Long End Type Public Declare Function TrackMouseEvent Lib "user32" (lpEventTrack As TRACKMOUSEEVENTTYPE) As Long Public Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 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 Public Const GWL_WNDPROC = (-4) Public PrevProc As Long Public Sub HookForm(F As Control) PrevProc = SetWindowLong(F.hWnd, GWL_WNDPROC, AddressOf WindowProc) End Sub Public Sub UnHookForm(F As Control) SetWindowLong F.hWnd, GWL_WNDPROC, PrevProc End Sub Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If uMsg = WM_MOUSELEAVE Then 'if we receive a WM_MOUSELEAVE message, show it Form1.Print "The mouse left the button!" End If WindowProc = CallWindowProc(PrevProc, hWnd, uMsg, wParam, lParam) End Function -------------------------------------------------------------------------------- into a form visual basic code:--------------------------------------------------------------------------------Private Sub command1_Click() Dim ET As TRACKMOUSEEVENTTYPE 'initialize structure ET.cbSize = Len(ET) ET.hwndTrack = Command1.hWnd ET.dwFlags = TME_LEAVE 'start the tracking TrackMouseEvent ET 'show a message to the user Me.Print "Move the mouse cursor outside the button" + vbCrLf + "to generate a WM_MOUSELEAVE event" End Sub Private Sub Form_Load() MsgBox "WARNING: This sample uses subclassing." + vbCrLf + "To end this program, always use the X button of the form." + vbCrLf + "Do not use VB's Stop button and do not use the 'End' keyword in your VB code." + vbCrLf + vbCrLf + "For more information about subclassing, check out" + vbCrLf + "our subclassing tutorial at http://www.allapi.net/", vbExclamation 'set the graphics mode to persistent Me.AutoRedraw = True Me.Print "Click the button to begin" 'start subclassing this form HookForm Command1 End Sub Private Sub Form_Unload(Cancel As Integer) 'stop subclassing this control UnHookForm Command1 End Sub




Reply With Quote