AW: Fensterln?
17.07.2017 10:41:31
mmat
Hallo Tom,
anbei der Code. Der findet das erste Fenster, bei dem ".pdf" in der Titelzeile auftaucht. Ich hab das mal auf das wesentliche eingedampft: so geht das. Je nach Umfeld und Einsatzzweck sind hier noch eine Menge Details auszuarbeiten, aber das überlass ich Dir :-)
vg, MM
Option Explicit
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As _
Long) As Boolean
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal _
hwnd As Long) As Long
Dim fn As String
Public Sub SucheFenster()
Dim n As Long
fn = "keine"
EnumWindows AddressOf FindWindow, 0&
MsgBox "Geöffnete Datei: " + fn
End Sub
Private Function FindWindow(ByVal lHwnd As Long, ByVal lParam As Long) As Boolean
Dim sTemp As String, retVal As Long, p As Long
retVal = GetWindowTextLength(lHwnd)
sTemp = Space(retVal)
GetWindowText lHwnd, sTemp, retVal + 1
If retVal 0 Then
p = InStr(UCase(sTemp), ".PDF")
If (p > 0) Then fn = Left(sTemp, p + 3): FindWindow = False: Exit Function
End If
FindWindow = True
End Function