VB 鼠标控制
展开全部
form1添加两个command控件和一个timer控件,添加如下代码:
Dim
moulast
As
POINTAPI
Dim
moubegin
As
POINTAPI
Dim
MoveCount
As
Integer
Dim
mousestep
As
POINTAPI
Private
Sub
Command1_MouseUp(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
MsgBox
("你按下了Command1键")
Timer1.Enabled
=
False
End
Sub
Private
Sub
Command2_Click()
Dim
destrect
As
RECT
'获得Command1在屏幕上的坐标。
GetWindowRect
Command1.hwnd,
destrect
'获得要移动到的位置的光标的坐标。
moulast.X
=
destrect.Left
moulast.Y
=
destrect.Top
'获得当前光标的坐标。
GetCursorPos
moubegin
Timer1.Enabled
=
True
stepx
=
moulast.X
-
moubegin.X
stepy
=
moulast.Y
-
moubegin.Y
mousestep
=
moubegin
End
Sub
Private
Sub
Timer1_Timer()
mousestep.X
=
mousestep.X
+
15
mousestep.Y
=
mousestep.Y
+
10
SetCursorPos
mousestep.X,
mousestep.Y
If
mousestep.X
>
moulast.X
And
mousestep.Y
>
moulast.Y
Then
Timer1.Enabled
=
False
SendMessage
Command1.hwnd,
WM_LBUTTONUP,
10,
10
End
If
End
Sub
Module1代码:
Public
Type
RECT
Left
As
Long
Top
As
Long
Right
As
Long
Bottom
As
Long
End
Type
Public
Type
POINTAPI
X
As
Long
Y
As
Long
End
Type
Public
Const
WM_LBUTTONUP
=
&H202
Public
Declare
Function
GetWindowRect
Lib
"user32"
(ByVal
hwnd
As
Long,
lpRect
As
RECT)
As
Long
Public
Declare
Function
SetCursorPos
Lib
"user32"
(ByVal
X
As
Long,
ByVal
Y
As
Long)
As
Long
Public
Declare
Function
GetCursorPos
Lib
"user32"
(lpPoint
As
POINTAPI)
As
Long
Public
Declare
Function
SendMessage
Lib
"user32"
Alias
"SendMessageA"
(ByVal
hwnd
As
Long,
ByVal
wMsg
As
Long,
ByVal
wParam
As
Long,
lParam
As
Any)
As
Long
Dim
moulast
As
POINTAPI
Dim
moubegin
As
POINTAPI
Dim
MoveCount
As
Integer
Dim
mousestep
As
POINTAPI
Private
Sub
Command1_MouseUp(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
MsgBox
("你按下了Command1键")
Timer1.Enabled
=
False
End
Sub
Private
Sub
Command2_Click()
Dim
destrect
As
RECT
'获得Command1在屏幕上的坐标。
GetWindowRect
Command1.hwnd,
destrect
'获得要移动到的位置的光标的坐标。
moulast.X
=
destrect.Left
moulast.Y
=
destrect.Top
'获得当前光标的坐标。
GetCursorPos
moubegin
Timer1.Enabled
=
True
stepx
=
moulast.X
-
moubegin.X
stepy
=
moulast.Y
-
moubegin.Y
mousestep
=
moubegin
End
Sub
Private
Sub
Timer1_Timer()
mousestep.X
=
mousestep.X
+
15
mousestep.Y
=
mousestep.Y
+
10
SetCursorPos
mousestep.X,
mousestep.Y
If
mousestep.X
>
moulast.X
And
mousestep.Y
>
moulast.Y
Then
Timer1.Enabled
=
False
SendMessage
Command1.hwnd,
WM_LBUTTONUP,
10,
10
End
If
End
Sub
Module1代码:
Public
Type
RECT
Left
As
Long
Top
As
Long
Right
As
Long
Bottom
As
Long
End
Type
Public
Type
POINTAPI
X
As
Long
Y
As
Long
End
Type
Public
Const
WM_LBUTTONUP
=
&H202
Public
Declare
Function
GetWindowRect
Lib
"user32"
(ByVal
hwnd
As
Long,
lpRect
As
RECT)
As
Long
Public
Declare
Function
SetCursorPos
Lib
"user32"
(ByVal
X
As
Long,
ByVal
Y
As
Long)
As
Long
Public
Declare
Function
GetCursorPos
Lib
"user32"
(lpPoint
As
POINTAPI)
As
Long
Public
Declare
Function
SendMessage
Lib
"user32"
Alias
"SendMessageA"
(ByVal
hwnd
As
Long,
ByVal
wMsg
As
Long,
ByVal
wParam
As
Long,
lParam
As
Any)
As
Long
武义菲亚伏电子有限公司
2023-06-12 广告
2023-06-12 广告
绝缘子控件是指:“一种能够在架空输电线路中起到重要作用的特殊绝缘控件,能够在架空输电线路中起到重要作用。”绝缘子的作用是支持和固定母线与带电导体,并使带电导体间或导体与大地之间有足够的距离和绝缘。绝缘子应具有足够的电气绝缘强度和耐潮湿性能。...
点击进入详情页
本回答由武义菲亚伏电子有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询