AW: Prüfen ob Acrobat Reader geöffnet ist
01.12.2006 15:10:25
Heiko
Hallo Erwin,
wenn du Reader Version 7 hast dann z.B. so. Alles in ein allgemeines Modul und dann das Makro Test starten
Option Explicit
' alle benötigten API's
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" ( _
ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal wIndx As Long) As Long
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Const GWL_STYLE = (-16)
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Public Function GetWindowList(strTest As String) As Long
' Wenn Fenster gefunden dan Whandle zurückgeben
' Wenn nicht dann -1 zurückgeben
Dim hwnd As Long
Dim strClassName As String * 100
Dim lngReturnLength As Long, lStyle As Long
' Erstes WindowHandle holen
hwnd = GetWindow(FindWindow(vbNullString, Application.Caption), GW_HWNDFIRST)
Do
' Handle auswerten und im ListView eintragen
lStyle = GetWindowLong(hwnd, GWL_STYLE)
lStyle = lStyle And (WS_VISIBLE Or WS_BORDER)
If (lStyle = (WS_VISIBLE Or WS_BORDER)) = True Then
lngReturnLength = GetClassName(hwnd, strClassName, 100)
If lngReturnLength > 0 Then
If InStr(1, strClassName, strTest) > 0 Then
GetWindowList = hwnd
Exit Function
End If
End If
End If
' Nächses Handle
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop Until hwnd = 0
GetWindowList = -1
End Function
Sub Test()
' Testen ob AcrobatReader geöffnet ist
If GetWindowList("AdobeAcrobat") <> -1 Then
MsgBox "Reader auf!", vbInformation
Else
MsgBox "Reader zu!", vbCritical
End If
End Sub
Gruß Heiko
PS: Rückmeldung wäre nett !