AW:Zusatzinfo
10.06.2009 14:15:12
chris
Hallo, ich habe jetzt zusätzlich etwas versucht.
und zwar habe ich aus dem Forum diesen Code irgendwann einmal erstellt.
Mit dem code kann ich in einer Exceldatei wählen ob ich NUR sichtbare oder alle fenster untereinander angezeigt bekommen möchte.
Das SAP fenster das ich aktivieren möchte wird aber komischerweiße nur gefunden wenn ich alle fenster anzeigen wähle also auch die Unsichtbaren.
Nur warum verstehe ich nicht.Das SAP Fenster ist ja nicht unsichtbar ich sehe es unten in meiner taskleiste ?
Vielen Dank noch einmal.
Hier der code der Datei die mir die fenster anzeigt:
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hWnd As Long, ByVal wCmd As Long) 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 GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
LParam As Any) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hWnd As Long) _
As Long
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hWnd As Long, ByVal wIndx As _
Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Const WM_CLOSE = &H10
Const GWL_STYLE = (-16)
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Public Function ListAll( _
Optional bolKill As Boolean = False, Optional KillHWND As Long)
Dim hWnd As Long, A As Long
Dim Titel$, Result$
A = Cells(Rows.Count, 1).End(xlUp).Row
hWnd = GetDesktopWindow()
hWnd = GetWindow(hWnd, GW_CHILD)
Do While hWnd 0
Style = GetWindowLong(hWnd, GWL_STYLE)
Style = Style And (WS_VISIBLE Or WS_BORDER)
Result = GetWindowTextLength(hWnd) + 1
Titel = Space$(Result)
Result = GetWindowText(hWnd, Titel, Result)
Titel = Left$(Titel, Len(Titel) - 1)
If bolKill = False Then
If (Style = (WS_VISIBLE Or WS_BORDER) Or Tabelle1.CheckBox1 = False) Then
If Titel > "" Then
A = A + 1
Cells(A, 1) = Titel
Cells(A, 2) = hWnd
End If
End If
Else
If hWnd = KillHWND And bolKill = True Then
PostMessage hWnd, WM_CLOSE, 0&, 0&
On Error Resume Next
AppActivate (Titel)
On Error GoTo 0
Exit Function
End If
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT) ' nächstes Fenster
Loop
End Function
Private Sub CommandButton1_Click()
Call LeseMeTask
End Sub
Sub LeseMeTask()
Cells.ClearContents
Range("A1") = "Titel": Range("B1") = "Window-Handle"
ListAll
Cells.Columns.AutoFit
'Call Sortiere
End Sub
Sub VersucheKillTask()
For A = 1 To Selection.Count
If Selection(A).Column = 1 And (Selection(A) > "" And _
Selection(A).Offset(0, 1) > 0) Then
ListAll True, Selection(A).Offset(0, 1)
End If
Next A
LeseMeTask
End Sub
'Dankeschön