用VB编一个程序:用来定时关闭另一个程序。
程序没有按钮,没有界面,当指定的一个程序启动时,计时器启动,当程序运行10分钟后,程序自动关闭,没有任何提示,直接关闭。请给出代码。谢谢...
程序没有按钮,没有界面,当指定的一个程序启动时,计时器启动,当程序运行10分钟后,程序自动关闭,没有任何提示,直接关闭。
请给出代码。谢谢 展开
请给出代码。谢谢 展开
3个回答
展开全部
这个是关闭一个网页的例子,关闭其他同理,仅供参考:
Private Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Dim hwnd1, hwnd2, hwnd3 As Long
Private Const WM_CLOSE As Long = &H10
Private Sub Timer1_Timer()
hwnd1 = FindWindow("IEFrame", "百度——全球最大中文搜索引擎 - Microsoft Internet Explorer")
Label1.Caption = hwnd1
If hwnd1 <> 0 Then
Call a
End If
End Sub
Sub a()
PostMessage& hwnd1, WM_CLOSE, 0&, 0&
End Sub
简单介绍:
hwnd1 = FindWindow("IEFrame", "百度——全球最大中文搜索引擎 - Microsoft Internet Explorer") '指定窗口名称
PostMessage& hwnd1, WM_CLOSE, 0&, 0& '发送关闭消息
Private Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Dim hwnd1, hwnd2, hwnd3 As Long
Private Const WM_CLOSE As Long = &H10
Private Sub Timer1_Timer()
hwnd1 = FindWindow("IEFrame", "百度——全球最大中文搜索引擎 - Microsoft Internet Explorer")
Label1.Caption = hwnd1
If hwnd1 <> 0 Then
Call a
End If
End Sub
Sub a()
PostMessage& hwnd1, WM_CLOSE, 0&, 0&
End Sub
简单介绍:
hwnd1 = FindWindow("IEFrame", "百度——全球最大中文搜索引擎 - Microsoft Internet Explorer") '指定窗口名称
PostMessage& hwnd1, WM_CLOSE, 0&, 0& '发送关闭消息
展开全部
把窗体的visible属性设置为false,添加一个timer控件,然后复制如下代码
Private Sub Form_Load()
Timer1.Interval = 10000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
End
End Sub
Private Sub Form_Load()
Timer1.Interval = 10000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
End
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这还不简单,都知道用计时器了,那很容易的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询