如何得知Mouse已离开某物件(二)
来源:cww 叁考 王国荣先生的作法
上一回使用mouse Hook的方式来Check Mouse是否已离开某物件,详见
如何得知Mouse已离开某物件(Mouse Hook)但使用这个方法太麻
烦了,改用SetCapture 来使Mouse的Message转到某个Window之上,如此,不管Mouse移动
於何处,都会将Mouse Input Message传给某个Window,最後使用ReleaseCapture来取消这
个作用。Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_Click()
Command1.Tag = ""
End SubPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Command1.Tag = "In" Then
If X < 0 Or Y < 0 Or X > Command1.Width Or Y > Command1.Height Then
Command1.Tag = ""
ReleaseCapture
Command1.Caption = "离开"
End If
Else
Command1.Tag = "In"
SetCapture Command1.hwnd
Command1.Caption = "进入"
End IfEnd Sub
来源:cww 叁考 王国荣先生的作法
上一回使用mouse Hook的方式来Check Mouse是否已离开某物件,详见
如何得知Mouse已离开某物件(Mouse Hook)但使用这个方法太麻
烦了,改用SetCapture 来使Mouse的Message转到某个Window之上,如此,不管Mouse移动
於何处,都会将Mouse Input Message传给某个Window,最後使用ReleaseCapture来取消这
个作用。Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_Click()
Command1.Tag = ""
End SubPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Command1.Tag = "In" Then
If X < 0 Or Y < 0 Or X > Command1.Width Or Y > Command1.Height Then
Command1.Tag = ""
ReleaseCapture
Command1.Caption = "离开"
End If
Else
Command1.Tag = "In"
SetCapture Command1.hwnd
Command1.Caption = "进入"
End IfEnd Sub
解决方案 »
- 谁能告诉我怎么给MSflexGrid控件插入列标题
- 又有200分了,散之……
- 急!!![ADO]当把CursorLocation设成adClient并更新时提示“缺少更新或刷新的键列信息”!
- 初学提问,关于报表.
- 关于用时间插件选择数据库中的一段时间删除?
- 团结就是力量 我不认输 进者给分 免费放送经典的娱乐搞笑 各位兄弟姐妹 你们辛苦了 工作之余 记得休息哦
- 报表设计器中报表宽度大于纸的宽度如何解决,急急急!!!!up有分
- 分辨率问题
- 局域网内怎样实现广播功能?
- Excel组件中为什么没有这个方法。在线等待。
- 大家都会遇到的问题:程序打包以后太大!!!!请大家来讨论、解决!来着有份!
- 关于用vb编计算器的问题
dim m as Integer Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
m = 1
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
m = 0
End Sub如果M=1then鼠标还在控件上。此法对控件之间有一定的距离就有效。
或MousePointer设置成指定的形状,MouseIcon不设置,
当鼠标移动到控件上时鼠标变为指定样式,就知道是否在该空间上。
这个办法比较简单。