I'm trying to make a simple shutdown program, but it takes my slow computer to shutdown 5-10 big programs, so to save time I want the program to shutdown all open windows for me. I'v got a code to close the window, but how would I get a list of open windows and maybe put them in an array.
Shutdown code:
In module
VB Code:
Option Explicit Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _ (ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long Private Declare Function EnumWindows Lib "user32.dll" _ (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long 'close apps Private Const WM_CLOSE = &H10 Private Const WM_QUIT = &H12 Private Target As String ' Check a returned task to see if we should kill it. Private Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long Dim buf As String * 256 Dim title As String Dim length As Long ' Get the window's title. length = GetWindowText(app_hWnd, buf, Len(buf)) title = Left$(buf, length) ' See if this is the target window. If InStr(title, Target) <> 0 Then ' Kill the window. SendMessage app_hWnd, WM_CLOSE, 0, 0 End If ' Continue searching. EnumCallback = 1 End Function ' Ask Windows for the list of tasks. Public Sub TerminateTask(app_name As String) Target = app_name EnumWindows AddressOf EnumCallback, 0 End Sub
Close code
VB Code:
TerminateTask "Microsoft Visual Basic"
Any help appreciated!![]()





Reply With Quote