VB中API问题

joan789987 2009-06-14 04:30:42
Form1中有两个按钮,按下一个按钮后,鼠标只能在窗体上移动,按下另一个按钮,鼠标只能在按钮上移动
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long

Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

privateType RECT
left As Long
top As Long
right As ong
bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type

Private Sub confineto(myctl As Object)
On Error Resume Next 这句什么意思啊?
Dim temprect As RECT 这两个定义什么意思
Dim pt As POINTAPI
With myctl
If TypeOf myctl Is Screen Then
tmprect.left = 0
tmprect.top = 0
tmprect.right = (.Width \ Screen.TwipsPerPixelX)
tmprect.bottom = (.Height \ Screen.TwipsPerPixelY)
ElseIf TypeOf myctl Is Form Then
tmprect.left = (.left \ Screen.TwipsPerPixelX)
tmprect.top = (.top \ Screen.TwipsPerPixelY)
tmprect.right = (.left + .Width) \ Screen.TwipsPerPixelX
tmprect.bottom = (.top + .Height) \ Screen.TwipsPerPixelY
(.Width \ Screen.TwipsPerPixelX)什么意思?
Else
pt.x = 0
pt.y = 0
Call ClientToScreen(.hwnd, pt) 什么来的?
tmprect.left = pt.x
tmprect.top = pt.y
pt.x = .Width \ Screen.TwipsPerPixelX
pt.y = .Height \ Screen.TwipsPerPixelY
Call ClientToScreen(.hwnd, pt)
tmprect.right = pt.x
tmprect.bottom = pt.y
End If
Call ClipCursor
End With
End Sub

Private Sub CmdButton_Click()
Static cliped As Boolean 用Boolean有什么用?
If Not cliped Then
confineto CmdButton
cliped = True
Else
confineto Screen
cliped = False
End If
End Sub

Private Sub CmdForm_Click()
Static cliped As Boolean
If Not cliped Then
confineto Form1
cliped = True
Else
confineto Screen
cliped = False
End If
End Sub

我有点看不懂,哪位高手教教我

...全文
59 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
joan789987 2009-06-15
  • 打赏
  • 举报
回复
谢谢哦
贝隆 2009-06-14
  • 打赏
  • 举报
回复
学习
一笑拔剑 2009-06-14
  • 打赏
  • 举报
回复
tmprect.bottom = (.top + .Height) \ Screen.TwipsPerPixelY
(.Width \ Screen.TwipsPerPixelX)什么意思?
这里就是通过计算得知上面那个控制鼠标范围的RECT值
Call ClientToScreen(.hwnd, pt) 什么来的
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
调用你最开头声明的这个api

Static cliped As Boolean 用Boolean有什么用?
这个就是判断是否禁止鼠标的

按第一下的时候
就运行then的语句
confineto Form1
cliped = True
这个cliped变成了true
当你再按的时候
他就运行else里的语句了
一笑拔剑 2009-06-14
  • 打赏
  • 举报
回复
Dim temprect As RECT 这两个定义什么意思
这个是一个范围

你看上面
privateType RECT
left As Long
top As Long
right As ong
bottom As Long
End Type

定义了上下左右的坐标

On Error Resume Next 这句什么意思啊?

这个是跳过错误的意思error错误的意思

1,488

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧