为何我用GetCursorPos得到的鼠标位置和计算的鼠标位置有这么大的差距!!!
我在我的control中想通过计算无hWnd控件的各个点的位置来确定鼠标是否在该控件区域内,却发现GetCursorPos得到的鼠标位置和计算的鼠标位置不一样,下面是我程序的原码,请大家帮忙参考。谢谢!!!
Private m_frmParent As Form
Private m_Left As Long
Private m_Top As Long
Private m_Right As Long
Private m_Bottom As Long
Private m_Point As POINTAPI
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'我的control只在form中,不在form中的其它容器内
Set m_frmParent = UserControl.Extender.Parent
With m_frmParent
m_Left = .Left / Screen.TwipsPerPixelX
m_Top = .Top / Screen.TwipsPerPixelY
End With
With UserControl.Extender
If m_frmParent.ScaleMode = vbTwips Then
m_Left = m_Left + .Left / Screen.TwipsPerPixelX
m_Top = m_Top + .Top / Screen.TwipsPerPixelY
ElseIf m_frmParent.ScaleMode = vbPixels Then
m_Left = m_Left + .Left
m_Top = m_Top + .Top
End If
End With
With Label1
m_Left = m_Left + .Left
m_Top = m_Top + .Top
m_Right = m_Left + .Width
m_Bottom = m_Top + .Height
End With
Call GetCursorPos(m_Point)
If (m_Point.x > m_Left And m_Point.y < m_Right) And _
(m_Point.y > m_Top And m_Point.y < m_Bottom) Then
Label1.BackColor = vbRed
Label1.Caption = "mouse is in client"
Else
Label1.BackColor = vbBlue
Label1.Caption = "mouse is not in client"
End If
End Sub