AW: Internetseite aufrufen und wieder schlie
10.11.2020 19:46:25
volti
Hallo Reiner,
hier ein Beispiel, wie Du eine Anwendung schließen kannst, wenn Dir der Caption nicht komplett bekannt ist. Wäre er bekannt, ging's auch einfacher....
Allerdings schließt er wohl komplett den Browser und die Seite musss aktiv sein. Ich habe nur unter Edge getestet.
Vielleicht bringt Dich das ja weiter:
Code:
[Cc][+][-]
Private Declare PtrSafe Function GetForegroundWindow Lib "user32" () As LongPtr
Private Declare PtrSafe Function GetWindow Lib "user32" ( _
ByVal hwnd As LongPtr, ByVal wCmd As Long) As LongPtr
Private Declare PtrSafe Function GetWindowTextLengthA Lib "user32" ( _
ByVal hwnd As LongPtr) As Long
Private Declare PtrSafe Function GetWindowTextA Lib "user32" ( _
ByVal hwnd As LongPtr, ByVal lpString As String, _
ByVal cch As Long) As Long
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 Const WM_CLOSE = &H10
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Dim hwnd As LongPtr
Sub CloseWebSite()
'Schließt eine Anwendung
Dim Text As String, L As Long
'Alle Fenster durchscannen
hwnd = GetWindow(GetForegroundWindow(), GW_HWNDFIRST)
Do While hwnd <> 0
L = GetWindowTextLengthA(hwnd) + 1
Text = Space$(L)
L = GetWindowTextA(hwnd, Text, L)
If Text Like "*Weltzeit*" Then
PostMessageA hwnd, WM_CLOSE, 0&, 0&
Exit Do
End If
DoEvents
hwnd = GetWindow(hwnd, GW_HWNDNEXT) 'Handle des nächsten Fensters
Loop
End Sub
_________________________
viele Grüße aus Freigericht 😊
Karl-Heinz