Dim x As Integer
Dim y As Integer
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Sub Command1_Click()
Dim PID As Long
GetWindowThreadProcessId Me.hwnd, PID
MsgBox "窗口进程的ID是:" & PID
End Sub
Private Sub Timer1_Timer()
Dim WindowHandle As Long
Randomize
x = Rnd() * 100
y = Rnd() * 100
WindowHandle = SetCursorPos(x, y)
End Sub