There is a way without having to use MouseMove, but it is quite complex.
Code:'BAS Module: Option Explicit Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal ndx As Long, ByVal newValue 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 Private Const GWL_WNDPROC = -4 Private Const WM_SETCURSOR = &H20 Private Const WM_MOUSEMOVE = &H200 Private saveHWnd As Long ' The handle of the subclassed window. Private oldProcAddr As Long ' The address of the original window procedure Private ChangehWnd As Long Sub StartSubclassing(ByVal hWnd As Long, hWndChange As Long) ChangehWnd = hWndChange saveHWnd = hWnd oldProcAddr = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WndProc) End Sub Sub StopSubclassing() SetWindowLong saveHWnd, GWL_WNDPROC, oldProcAddr End Sub Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long WndProc = CallWindowProc(oldProcAddr, hWnd, uMsg, wParam, lParam) Select Case uMsg Case WM_SETCURSOR Dim ctrlHWnd As Long Dim mouseAction As Long Dim ctrl As Control ' wParam holds the handle of the control under the cursor ctrlHWnd = wParam ' code for mouse action is in high word of lParam mouseAction = (lParam \ &H10000) If mouseAction = WM_MOUSEMOVE Then If wParam = ChangehWnd Then Form1.BackColor = vbYellow Else: Form1.BackColor = vbBlue End If End If End Select End FunctionI hope this is near to what you need.Code:Form called Form1, with a textbox called Text1: Private Sub Form_Load() StartSubclassing Me.hWnd, Text1.hWnd End Sub Private Sub Form_Unload(Cancel As Integer) StopSubclassing End Sub
Me




Reply With Quote