Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1140to1144
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Fesnster im Vordergrund prüfen

Fesnster im Vordergrund prüfen
marspoki
Hallo,
habe mal eine kurze Frage,
ich möchte gerne Püfen ob ein externes Fenster im Vordergrund ist. Fenstername ist "RLPD"
Gibt es da eine Möglichkeit? Vielen Dank schonmal an euch!!
gruß
Sebastian
ich würde mir das so vorstellen!
if "das fenster mit namen "RLPD" im vordergrund = True Then
msgBOX "1"
Else
msgBox "2"
End if

3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Fesnster im Vordergrund prüfen
04.03.2010 15:20:38
xr8k2
Hallo marspoki,
versuch mal sowas:
Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Sub FensterImVordergrund()
Dim Pufferlänge As Long, Puffer As String, Fensterhandle As Long
AppActivate ("Krebis - Grunddaten Objekt")
Fensterhandle = GetForegroundWindow
Pufferlänge = GetWindowTextLength(Fensterhandle) + 1
Puffer = Space(Pufferlänge)
Pufferlänge = GetWindowText(GetForegroundWindow, Puffer, Pufferlänge)
If Left$(Puffer$, Pufferlänge) = "RLPD" Then
MsgBox "1"
Else
MsgBox "2"
End If
End Sub
--> Quelle tlw. http://www.vbarchiv.net
Gruß,
xr8k2
Anzeige
AW: Fesnster im Vordergrund prüfen
05.03.2010 09:33:01
marspoki
Das geht leider nicht wie erhofft.
ich nutuze zur zeit folgenden Code:
Ich muss es irgendwie schaffen zu Prüfen ob das Fenster offen und aktiv ist.
Please Help
Option Explicit
Private Declare Function SetForegroundWindow _
Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hwnd As Long) _
As Long
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 GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal wIndx As _
Long) As Long
Private Declare Function ShowWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Const GWL_STYLE& = (-16)
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Const GW_HWNDNEXT& = 2
Const GW_CHILD& = 5
Const iNormal& = 1
Const iMinimized& = 2
Const iMaximized& = 3
Private Function GetWindowInfo(ByVal hwnd&, STitel$, Optional booVisible As Boolean = True) As  _
Long
Dim Result&, Style&, Title$
'Darstellung des Fensters
Style = GetWindowLong(hwnd, GWL_STYLE)
Style = Style And (WS_VISIBLE Or WS_BORDER)
'Fensetrtitel ermitteln
Result = GetWindowTextLength(hwnd) + 1
Title = Space$(Result)
Result = GetWindowText(hwnd, Title, Result)
Title = Left$(Title, Len(Title) - 1)
'prüfen ob Fenster Sichtbar
If (Style = (WS_VISIBLE Or WS_BORDER)) Or booVisible = False Then
If Title Like "*" & STitel & "*" Then
GetWindowInfo = hwnd
Exit Function
End If
End If
GetWindowInfo = 0
End Function

Sub Fenster_Aktivieren()
Dim hwnd As Long
Dim STitel As String
'hier einen Teil vom Titel angeben ******************
STitel = "RLPD"
hwnd = GetDesktopWindow()
hwnd = GetWindow(hwnd, GW_CHILD)
'2. Param. Fenstertitel (nur ein Teil erforderlich)
'3. Param. optional True nur Sichtbare, False alle
GetWindowInfo hwnd, STitel, False
Do While hwnd 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
If GetWindowInfo(hwnd, STitel, True) = hwnd Then
ShowWindow hwnd, iNormal 'maximieren
SetForegroundWindow hwnd 'aktivieren
End If
Loop
End Sub
Anzeige
AW: Fesnster im Vordergrund prüfen
06.03.2010 04:37:01
fcs
Hallo marspoki,
irgendwie ist die Prüflogik in deiner Do-Loop-Schleife nicht ganz korrekt.
Wenn du ein Makro von Excel aus startest, dann ist immer eines der Excel-Fenster das aktive Fenster. Ausnahme möglicherweise Excel OnTime-Methode oder Makros in denen ein ExcelApplication-Objekt die Eigenschaft Invisible hat.
Folgende Anpassung deiner Hauptprozedur zeigt an, ob eine Anwendung mit dem gesuchten Namen geöffnet ist.
Gruß
Franz
Sub Fenster_Aktivieren()
Dim hwnd As Long
Dim STitel As String
'hier einen Teil vom Titel angeben ******************
STitel = "Mozilla"
hwnd = GetDesktopWindow()
hwnd = GetWindow(hwnd, GW_CHILD)
'2. Param. Fenstertitel (nur ein Teil erforderlich)
'3. Param. optional True nur Sichtbare, False alle
GetWindowInfo hwnd, STitel, False
Do
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
If hwnd = 0 Then Exit Do
If GetWindowInfo(hwnd, STitel, True) = hwnd Then
MsgBox "Fenster mit """ & STitel & """ ist geöffnet" 'Test MsgBox
ShowWindow hwnd, iNormal 'maximieren
SetForegroundWindow hwnd 'aktivieren
Exit Sub
End If
Loop
MsgBox "Fenster mit """ & STitel & """ nicht vorhanden" 'Test MsgBox
End Sub

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige