代朋友问一个有关vb的问题(怎么把打开的窗口关了啊?)

fengstudios 2003-08-19 09:51:19
一个有关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 Type

Dim z As POINTAPI ' 变量

Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 20000

End Sub

Private 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 Double

Savetime = 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
...全文
27 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
射天狼 2003-08-19
  • 打赏
  • 举报
回复
GetActiveWindow你这是取得活动窗口的句柄,如果IE不是活动的,你能关了吗?
再有打开还用这么麻烦吗?
你是想干什么,思路好像有问题!
td427 2003-08-19
  • 打赏
  • 举报
回复
不好整得
aiur2000 2003-08-19
  • 打赏
  • 举报
回复
俺没做过,想象一下,先得到ie的hwnd,然后再调用api关掉他

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧