ich habe heute eine schwere frage und komme nicht weiter.
Würde mich sehr über Hilfe freuen.
Habe mit Hilfe des Forums(woher genau) weiß ich leider nicht mehr folgenden Code erstellt.
Dieser soll mir dazu dienen SAP Fenster zu aktivieren.
das klappt auch super.Aber leider weiß ich nicht wie ich prüfen kann ob das fenster jetzt aktiv ist oder nicht.
Mein Programm macht einfach weiter.
Egal ob fenster aktiv oder nicht.
Könnt ihr mir helfen und sagen was ich machen könnte das es erst weiter gehtw enn das fenster aktiv ist ? Und sonst nach z.b 5 sekunden abbricht ?
Vielen Dank im voraus
gruß Chris
Sub SAP_Makro()
'SAP Fenster aktivieren
Fenster_aktivieren "Material ändern"
''''''Mein Code ....
'SAP Fenster aktivieren
Fenster_aktivieren "testfenster"
'... weiter mein code
End Sub
Und in einem Extra Modul habe ich diesen code:
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
Public OK As Boolean
Const iNormal& = 1
'Const iMinimized& = 2
'Const iMaximized& = 3
Sub Fenster_aktivieren(FensterName)
Dim hwnd As Long
Dim STitel As String
STitel = FensterName 'hier einen Teil vom Fenster Titel angeben
hwnd = GetDesktopWindow()
hwnd = GetWindow(hwnd, GW_CHILD)
GetWindowInfo hwnd, STitel, False
Do While hwnd 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
If GetWindowInfo(hwnd, STitel, False) = hwnd Then ' False alle Fenster , true nur _
sichtbare Fenster
ShowWindow hwnd, iNormal&
SetForegroundWindow hwnd 'aktivieren
End If
Loop
End Sub
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