其中用到的模块代码为
Option Explicit
Declare Function EnumWindows Lib "user32" (ByVal wndenmprc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
Private Target As StringPublic Function closewin(ByVal app_hWnd As Long, ByVal param As Long) As Long
Dim buf As String * 256
Dim title As String
Dim length As Long '取得窗口名句柄
length = GetWindowText(app_hWnd, buf, Len(buf))
title = Left$(buf, length) '判断是否为要关闭的窗体
If InStr(title, Target) <> 0 Then
' 关闭窗体
SendMessage app_hWnd, WM_CLOSE, 0, 0
End If
closewin = 1
End FunctionPublic Sub pausetask(app_name As String)
Target = app_name
EnumWindows AddressOf closewin, 0
End Sub
Option Explicit
Declare Function EnumWindows Lib "user32" (ByVal wndenmprc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
Private Target As StringPublic Function closewin(ByVal app_hWnd As Long, ByVal param As Long) As Long
Dim buf As String * 256
Dim title As String
Dim length As Long '取得窗口名句柄
length = GetWindowText(app_hWnd, buf, Len(buf))
title = Left$(buf, length) '判断是否为要关闭的窗体
If InStr(title, Target) <> 0 Then
' 关闭窗体
SendMessage app_hWnd, WM_CLOSE, 0, 0
End If
closewin = 1
End FunctionPublic Sub pausetask(app_name As String)
Target = app_name
EnumWindows AddressOf closewin, 0
End Sub
是不是你不停的Shell并且每个都没有关闭导致的呀?
还有,查看任务栏显这个vb.exe程序的确一直在运行,而webbrowser.exe的确一会儿启动,一会儿关闭了,这有作何解释呢?
Un1的意思我不太懂,把webbrowser.exe作为ActiveX exe控制有何好处?
我和你一样有怀疑,这个函数pausetask就在上面,我也估计并没有真正关闭程序webbrowser.exe,但是把webbrowser.exe换成notepad.exe,确实发现notepad.exe关闭了窗口,我想问:关闭了notepade.exe窗口算不算结束了notepad.exe程序?应该算吧,那换成webbrowse.exe为何出现死机呢?各位看上面的pausetask函数,是否结束了一个程序呢?是暂停还是根本就结束了程序?
哪位大虾指点一下?
会不会是什么地方消耗了内存没有释放掉?
sleep 5000
timer1.enabled=true
Dim hwnd%, lResult, fl%, i% fl% = True Do
' The desktop is the highest window
hwnd% = GetDesktopWindow() ' It's first child is the 1st top level window
hwnd% = GetWindow(hwnd%, GW_CHILD) ' Now load all top level windows
Do
If GetWindowExename$(hwnd%) = UCase$(p$) Then
lResult = SendMessage(hwnd%, WM_CLOSE, 0, 0&)
fl% = True
Else
fl% = False
End If
hwnd% = GetWindow(hwnd%, GW_HWNDNEXT)
Loop While hwnd% <> 0
Loop While fl%
End Sub