问题描述
- 如何在vba中读取屏幕坐标,跪求,急
-
在vba里面没法添加timer控件,所以GetCursorPos貌似没法用,还有我试过mousemove,结果只能获得窗体的坐标,那如何获得屏幕的坐标呀,我的编程环境是coreldraw vba
解决方案
解决方案二:
用API实现定时器
增加一个module
增加代码
Option Explicit
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Public p As POINTAPI
Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
GetCursorPos p
UserForm1.setXY p
End Sub
增加一个Form,这里名字是userform1
代码如下
Option Explicit
Public Sub setXY(p As POINTAPI)
text_x.Text = CStr(p.x)
text_y.Text = CStr(p.y)
End Sub
Private Sub UserForm_Initialize()
Call SetTimer(0, 0, 10, AddressOf TimerProc)
End Sub
解决方案三:
GetCursorPos和timer没关系,它是api函数。可以直接调用的。
解决方案四:
moudle1:
Option Explicit
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Public p As POINTAPI
Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
UserForm1.Hide
GetCursorPos p
CoordintePick1.setXY p
UserForm1.Show
End Sub
Public Sub setXY(p As POINTAPI)
txtcenX2.Text = CStr(p.x)
txtcenY2.Text = CStr(p.y)
End Sub
Public Sub moudle1()
Load UserForm1
UserForm1.Show
End Sub
userform1
Option Explicit
Private Sub CoordintePick1_Initialize()
Call SetTimer(0, 0, 10, AddressOf TimerProc)
End Sub
我这样修改,但是不对,点击关闭应该用click属性吧,刚学vba,啥都不会
解决方案五:
setq a getpiont