01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 |
|
Option Explicit
Private Declare PtrSafe Function FindWindowA Lib "user32" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function PostMessageA Lib "user32" ( _
ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, _
ByVal lParam As LongPtr) As Long
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const WM_CLOSE = &H10
Sub CloseApp(sCaption As String, Optional sClassname As String)
' Schließt ein Fenster oder eine Dialogbox
Dim i As Integer, hwnd As LongPtr
Do
hwnd = FindWindowA(sClassname, sCaption) ' Handle des App-Fensters ermitteln
If hwnd <> 0 Then
PostMessageA hwnd, WM_CLOSE, 0&, 0& ' App schließen
Exit Sub
End If
Sleep 100
i = i + 1: If i > 60 Then Exit Do ' Timeout nach 60 Sekunden
Loop
End Sub
Sub Test()
CloseApp "Unbenannt - Editor" ' ,"Notepad"
End Sub
|