Das sollt etwa so gehe (leider nur VB, aber in Delphi sieht die API ja auch nicht viel anders aus…):
Public Const INFINITE = &HFFFF
Public Const PROCESS\_ALL\_ACCESS = &H1F0FFF
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpCaption As Any) As Long
Declare Function PostMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal InheritHandle As Long, ByVal dwProcessID As Long) As Long
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Sub CloseAppClass(Optional AppClass As String = "IEFrame")
Dim Lg As Long, lngRes As Long, hwnd As Long, hProcess As Long, s As String, idProc As Long
hwnd = GetDesktopWindow()
hwnd = GetWindow(hwnd, GW\_CHILD)
Do While hwnd 0
s = String(255, 0)
Lg = GetClassName(hwnd, s, Len(s)) ' Class holen
If Lg \> 0 Then
If left(s, Lg) = AppClass Then
lngRes = PostMessage(hwnd, WM\_CLOSE, 0&, 0&:wink:
lngRes = GetWindowThreadProcessId(hwnd, idProc)
hProcess = OpenProcess(PROCESS\_ALL\_ACCESS, 0, idProc)
lngRes = TerminateProcess(hProcess, 0&:wink:
End If
End If
hwnd = GetWindow(hwnd, GW\_HWNDNEXT)
Loop
End Sub
Reinhard