GetMouse.bas---------------------------------------------------------------------- Option ExplicitType POINTAPI X As Long Y As Long End Type'api声明 private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) _ As Longprivate Declare Function WindowFromPoint Lib "user32" _ (ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate Declare Function ScreenToClient Lib "user32" _ (ByVal hwnd As Long, lpPoint As POINTAPI) As LongPublic function GetMouseHwnd() as longDim lonCStat As Long Dim lonCurhWnd As Long Dim mpoiCursorPos As POINTAPI
'two API function '取得鼠标坐标 到mpoiCursorPos中。 lonCStat = GetCursorPos&(mpoiCursorPos) 'get mouse position'根据坐标找到对应该点的窗口句柄 getmousehwnd = WindowFromPoint(mpoiCursorPos.X, _ mpoiCursorPos.Y)
End function -------------------------------------------------------------------------------------if GetMouseHwnd=usercontrol.hwnd then msgbox "鼠标在控件上" else msgbox "不在"
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If GetMouseHwnd = UserControl.hwnd Then UserControl.BackColor = &H80000010 Else UserControl.BackColor = &H80000000 End If End Sub 我在MouseMove里面这样写的 为什么不行呢?鼠标移上去有变化,可当移出后不变回来啊。。
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If GetMouseHwnd = UserControl.hwnd Then UserControl.BackColor = &H80000010 Else UserControl.BackColor = &H80000000 End If End Sub因在退出时没有事件发生! not(GetMouseHwnd = UserControl.hwnd)不会出现!你用拖拉方式处理即可!
你在控件里放一个timer控件. 在Timer事件中写这段代码private sub Timer1_timer() If GetMouseHwnd = UserControl.hwnd Then UserControl.BackColor = &H80000010 Else UserControl.BackColor = &H80000000 End Ifend sub
Option ExplicitType POINTAPI
X As Long
Y As Long
End Type'api声明
private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) _
As Longprivate Declare Function WindowFromPoint Lib "user32" _
(ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate Declare Function ScreenToClient Lib "user32" _
(ByVal hwnd As Long, lpPoint As POINTAPI) As LongPublic function GetMouseHwnd() as longDim lonCStat As Long
Dim lonCurhWnd As Long
Dim mpoiCursorPos As POINTAPI
'two API function
'取得鼠标坐标 到mpoiCursorPos中。
lonCStat = GetCursorPos&(mpoiCursorPos) 'get mouse position'根据坐标找到对应该点的窗口句柄
getmousehwnd = WindowFromPoint(mpoiCursorPos.X, _
mpoiCursorPos.Y)
End function
-------------------------------------------------------------------------------------if GetMouseHwnd=usercontrol.hwnd then msgbox "鼠标在控件上" else msgbox "不在"
If GetMouseHwnd = UserControl.hwnd Then
UserControl.BackColor = &H80000010
Else
UserControl.BackColor = &H80000000
End If
End Sub
我在MouseMove里面这样写的
为什么不行呢?鼠标移上去有变化,可当移出后不变回来啊。。
这样不行的话,用screentoclient 将鼠标坐标转化成当前窗体坐标,判断一下就知道了
If GetMouseHwnd = UserControl.hwnd Then
UserControl.BackColor = &H80000010
Else
UserControl.BackColor = &H80000000
End If
End Sub因在退出时没有事件发生! not(GetMouseHwnd = UserControl.hwnd)不会出现!你用拖拉方式处理即可!
在Timer事件中写这段代码private sub Timer1_timer()
If GetMouseHwnd = UserControl.hwnd Then
UserControl.BackColor = &H80000010
Else
UserControl.BackColor = &H80000000
End Ifend sub