Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1176to1180
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

Nochmal Fenster Vordergrundprüfung

Nochmal Fenster Vordergrundprüfung
Sebastian
Hallo,
ich muß nochmal fragen bei der letzten Frage war leider mein Code nicht komplett.
Also ich hole mir mit den unten Aufgeführen Code das Windwos Fenster mit den NamenTV Sender in den Vordergrund.
Wenn das passiert ist möchte ich gerne ein weiters Makro ausführen, aber aber auch wirklich nur wenn das Passiert ist.
Irgendwie klann ich die Do While schleife nicht abbrechen.
Wie kann ich ein Makro ausführen, wenn der Fenstertitel gefunden wurde, bzw die schleife vor ausführung des nächsten Makros beenden lassen, wenn der Fenstertitel nicht existiert!?
Vielen Dank
Sebastian
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
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 FensterSuchen()
Dim hwnd As Long
Dim STitel As String
STitel = "TV Sender"
hwnd = GetDesktopWindow()
hwnd = GetWindow(hwnd, GW_CHILD)
GetWindowInfo hwnd, STitel, True
Do While hwnd 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
If GetWindowInfo(hwnd, STitel, True) = hwnd Then
ShowWindow hwnd, iNormal 'maximieren
SetForegroundWindow hwnd 'aktivieren
Dim Rec As RECT
GetWindowRect GetForegroundWindow, Rec
End If
Loop
'makro 1 soll jetzt starten, wenn das Fenster existiert
makro1
End Sub

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Nochmal Fenster Vordergrundprüfung
12.09.2010 13:38:12
Tino
Hallo,
baue Dir doch eine Variable ein die Du in der Schleife auf True setzt und Frage diese ab.
Sub FensterSuchen()
Dim hwnd As Long
Dim STitel As String
Dim Rec As RECT, booActiv As Boolean
STitel = "Herbers Excel*" ' "TV Sender"
hwnd = GetDesktopWindow()
hwnd = GetWindow(hwnd, GW_CHILD)
GetWindowInfo hwnd, STitel, True
Do While hwnd  0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
If GetWindowInfo(hwnd, STitel, True) = hwnd Then
ShowWindow hwnd, iNormal 'maximieren
SetForegroundWindow hwnd 'aktivieren
GetWindowRect GetForegroundWindow, Rec
booActiv = True
End If
Loop
'makro 1 soll jetzt starten, wenn das Fenster existiert
If booActiv Then call makro1
End Sub
Gruß Tino
Anzeige
AW: Nochmal Fenster Vordergrundprüfung
12.09.2010 14:23:01
Sebastian
mmh, ok der ansatz ist sicher nicht verkehrt, aber das Makro wird auch ausgeführt wenn das Fenster nicht das ist und genau das ist es was ich vermeiden will....
Hast du noch eine idee?
getestet...
12.09.2010 14:44:43
Tino
Hallo,
so müsste es gehen, habe es diesmal getestet.
Option Explicit
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long

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 FensterSuchen()
 Dim hwnd As Long, tmpHwnd&
 Dim STitel As String
 Dim Rec As RECT, booActiv As Boolean
 
 STitel = "Herbers Excel" ' "TV Sender" 
 
 hwnd = GetDesktopWindow()
 hwnd = GetWindow(hwnd, GW_CHILD)
 
 GetWindowInfo hwnd, STitel, True
 
 Do While hwnd <> 0
     hwnd = GetWindow(hwnd, GW_HWNDNEXT)
     tmpHwnd& = GetWindowInfo(hwnd, STitel, True)
     If tmpHwnd = hwnd And tmpHwnd <> 0 Then
         ShowWindow hwnd, iNormal 'maximieren 
         SetForegroundWindow hwnd 'aktivieren 
         GetWindowRect GetForegroundWindow, Rec
         booActiv = True
         Exit Do
     End If
 Loop
 
 'makro 1 soll jetzt starten, wenn das Fenster existiert 
 If booActiv Then Call Makro1
 
 End Sub


Sub Makro1()
MsgBox "geht"
End Sub
Gruß Tino
Anzeige
AW: getestet...
12.09.2010 15:02:07
Sebastian
WOW :-)
Vielen Dank
ich hatte es schon fast aufgegeben....
na dann zu
12.09.2010 16:16:48
zu

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige