Option Explicit
'获得整个窗口的范围矩形,窗口的边框、标题栏、滚动条及菜单等都在这个矩形内
Private Declare Function GetWindowRect Lib “user32” (ByVal Hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
'获取鼠标指针的当前位置
Private Declare Function GetCursorPos Lib “user32” (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
'返回包含了指定点的窗口的句柄。忽略屏蔽、隐藏以及透明窗口
Private Declare Function WindowFromPoint Lib “user32” (ByVal xPoint As Long, ByVal yPoint As Long) As Long
'判断鼠标是否在窗口(COX)范围内
Private Function IsMouseOver() As Boolean
Dim pt As POINTAPI
GetCursorPos pt
IsMouseOver = (WindowFromPoint(pt.X, pt.Y) = Hwnd)
End Function
'获得鼠标在桌面的坐标
Private Function CursorPosition() As POINTAPI
Dim pt As POINTAPI
GetCursorPos pt
CursorPosition.X = pt.X
CursorPosition.Y = pt.Y
End Function
'判断鼠标是否在控件(窗口)范围内
Private Function ControlRange(ByVal Hwnd As Long) As Boolean
Dim pt As RECT, Point As POINTAPI, CRge As Boolean
GetCursorPos Point
GetWindowRect Hwnd, pt
ControlRange = IIf(Point.X > pt.Left And Point.X < pt.Right And Point.Y > pt.Top And Point.Y < pt.Bottom, True, False)
End Function
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If ControlRange(Text1.Hwnd) Then
Text1.BackColor = RGB(255, 0, 0)
Else
Text1.BackColor = RGB(255, 255, 255)
Timer1.Enabled = False
End If
End Sub
本文发布于:2024-01-27 22:18:40,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063651202968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |