Type RECT
Left As Long '屏幕到目标窗口的左边距
Top As Long '屏幕到目标窗口的顶边距
Right As Long '屏幕到目标窗口的右边距
Bottom As Long '屏幕到目标窗口的底边距
End Type
教学代码:
'API声明
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Command1_Click()
Dim ck_hwnd As Long '定义计算器窗口句柄变量
ck_hwnd = FindWindow("SciCalc", "计算器") 'SciCalc 取计算器窗口句柄
Text1.Text = Str(ck_hwnd)
Dim ck_R As RECT
If ck_hwnd <> 0 Then
GetWindowRect ck_hwnd, ck_R ' 取计算器窗口矩形范围坐标,或左上角坐标及右下角坐标
Label2.Caption = Str(ck_R.Left) & Str(ck_R.Top) & Str(ck_R.Right) & Str(ck_R.Bottom)
SetCursorPos 350 + ck_R.Left, 150 + ck_R.Top '设置鼠标指针
'mouse_event()
End If
End Sub