一个有关vb的问题(怎么把打开的窗口关了啊?)请高手们指定一下,我的这个程序会每隔20秒鼠标会在170,63这个位置双击打开一个IE窗口,然后将它关闭。但是有点问题,不能关闭?请帮忙改正一下!谢了
Option Explicit'申明API函数
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Type POINTAPI ' 声明数据类型
x As Long
y As Long
End TypeDim z As POINTAPI ' 变量Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 20000End SubPrivate Sub Timer1_Timer()
GetCursorPos z ' 获取坐标
Label1.Caption = "x: " & z.x ' 显示 x 坐标
Label2.Caption = "y: " & z.y ' 显示 y 坐标
SetCursorPos 170, 63 ' (X, Y) 为欲设定的鼠标座标,座标单位是 Pixel(像素)4461
Dim Savetime As DoubleSavetime = timeGetTime '记下开始时的时间
While timeGetTime < Savetime + 5000 '循环等待
DoEvents '转让控制权,以便让*作系统处理其它的事件。
Wend
mouse_event &H2 Or &H4, 0, 0, 0, 0
mouse_event &H2 Or &H4, 0, 0, 0, 0  '双击打开一个IE窗口
Dim winHwnd As Long
Savetime = timeGetTime '记下开始时的时间
While timeGetTime < Savetime + 5000 '循环等待
DoEvents '转让控制权,以便让*作系统处理其它的事件。
Wend
winHwnd = GetActiveWindow
Label3.Caption = winHwnd
SetCursorPos z.x, z.y
Savetime = timeGetTime '记下开始时的时间
While timeGetTime < Savetime + 5000 '循环等待
DoEvents '转让控制权,以便让*作系统处理其它的事件。
Wend
PostMessage winHwnd, WM_CLOSE, 0&, 0&
End Sub
Private Sub Command1_Click()
Unload Me
end sub