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

Beitrag noch offen Appactivate - Bitte um Hilfe

Beitrag noch offen Appactivate - Bitte um Hilfe
16.06.2009 07:13:36
chris
Hallo VBA Experten und Forumsbesucher,
ich benötige Hilfe.Bis jetzt wurde mir hier auch immer sehr gut geholfen.
Es geht um den Beitrag Appactivate den ich vor meheren Tagen noch einmal offen gesetzt habe.
Habe da auch einen guten Beitrag von Luschi bekommen.Mit dem ich aber alleine nicht klar komme.
Deshalb bitte ich euch um hilfe.
Hier der Link zu dem Beitrag. vielen Dank im vorraus an alle Helfer.
https://www.herber.de/forum/messages/1080914.html

12
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
vielleicht geht’s hiermit.
16.06.2009 08:05:25
Tino
Hallo,
hier mal eine andere Variante um ein Fenster erst auf die Normale größe zu bringen und danach in den Vordergrund zu bringen.
Bei STitel, musst Du den Titel (einen Teil davon) den das Fensters hat angeben.
kommt als Code in Modul1
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 
 
  STitel = "Internet Explorer" 'hier einen Teil vom Titel angeben 
 
  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, True 
 
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 
 


Gruß Tino

Anzeige
AW: vielleicht geht’s hiermit.andere möglichkeit?
16.06.2009 08:11:40
chris
Hallo Tino,
vielen Dank für dein Hilfe.
Klappt aber nicht:(
Ich denke das liegt an dem SAP Fenster selbst.
Weil wenn ich es maximiere hat es keinen Titel.
Also oben in der Fensterleiste steht kein Titel.
Wenn ich aber ich der Taskleiste über das Fenster fahre erscheit der Titel.
Weißt du vielleicht oder irgend jemand noch eine möglichkeit ?
Danke vielmals im vorraus
Bei mir gehts mit jeder Anwendung...
16.06.2009 08:17:27
Tino
Hallo,
mach mal aus der Zeile
GetWindowInfo hwnd, STitel, True
diese
GetWindowInfo hwnd, STitel, False
Sollte dies nicht gehen kann ich dir auch nicht helfen ohne Deine Anwendung zu kennen.
Gruß Tino
Anzeige
AW: Bei mir gehts mit jeder Anwendung...
16.06.2009 08:24:14
Tino
Hallo,
bei If GetWindowInfo(hwnd, STitel, True) = hwnd Then musst Du auch noch False angeben,
also If GetWindowInfo(hwnd, STitel, False) = hwnd Then
Was steht bei Dir im Taskmanager für ein Titel und wie gibst Du den Titel unter sTitel an,
hast Du die Groß und Kleinschreibung beachtet?
Gruß Tino
noch eine letzte Hilfestellung.
16.06.2009 08:53:02
Tino
Hallo,
ich habe den Verdacht, dass Du nicht nach dem richtigen Fenstertitel suchst.
Mach mal eine neue Datei, fügen diesen Code in ein Modul ein und starten die Sub vList_Prozesse.
Kannst Du Deine Anwendung mit dem Titel in der Liste finden?
Solltest Du Deine Anwendung finden, verwende diesen Titel.
Option Explicit
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 GetWindowText Lib "user32" _
        Alias "GetWindowTextA" _
        (ByVal hWnd As Long, ByVal lpString As String, _
        ByVal cch 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 GetWindowTextLength Lib "user32" _
        Alias "GetWindowTextLengthA" (ByVal hWnd As Long) _
        As Long

Private Declare Function GetWindowThreadProcessId Lib "user32" _
        (ByVal hWnd As Long, lpdwProcessId 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 GetParent Lib "user32" (ByVal hWnd _
        As Long) As Long
        
        
Const GW_HWNDFIRST = 0
Const GW_HWNDLAST = 1
Const GW_HWNDNEXT = 2
Const GW_HWNDPREV = 3
Const GW_OWNER = 4
Const GW_CHILD = 5
Const GW_MAX = 5

Const GWL_STYLE = (-16)

Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Private Sub GetWindowInfo(ByVal hWnd&, bVisible As Boolean, booMit_Titel As Boolean)
  Dim Parent&, Task&, Result&, X&, Style&, Title$
  
    'Darstellung des Fensters 
    Style = GetWindowLong(hWnd, GWL_STYLE)
    Style = Style And (WS_VISIBLE Or WS_BORDER)

    Result = GetWindowTextLength(hWnd) + 1
    Title = Space$(Result)
    Result = GetWindowText(hWnd, Title, Result)
    Title = Left$(Title, Len(Title) - 1)
    
   If (Style = (WS_VISIBLE Or WS_BORDER)) Or bVisible = False Then
     
     If Title <> "" Or booMit_Titel = False Then
      
      Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = CStr(hWnd)
      Cells(Rows.Count, 2).End(xlUp).Offset(1, 0) = Title
      
      'Elternfenster ermitteln 
      Parent = hWnd
      Do
        Parent = GetParent(Parent)
      Loop Until Parent = 0
      
      'Task Id ermitteln 
      Result = GetWindowThreadProcessId(hWnd, Task)
      Cells(Rows.Count, 3).End(xlUp).Offset(1, 0) = Task
     
     End If
  End If
End Sub
Sub vList_Prozesse()
Dim hWnd As Long, tbuf As String, RetVal As Long


'Zellen leeren und Überschrift 
Cells.Clear
Range("A1") = "hwnd"
Range("B1") = "Titel"
Range("C1") = "Prozess ID"
Range("A1:C1").Font.Bold = True
'______________________________
 
'hwnd Deskdopt 
  hWnd = GetDesktopWindow()
  hWnd = GetWindow(hWnd, GW_CHILD)
'hwnd, nur Sichtbar, nur Mit Fenstertitel 
  GetWindowInfo hWnd, True, True

Do While hWnd <> 0
    tbuf = String(255, 0)
    RetVal = GetWindowText(hWnd, tbuf, Len(tbuf))
    hWnd = GetWindow(hWnd, GW_HWNDNEXT)
    'hwnd, nur Sichtbar, nur mit Fenstertitel 
    GetWindowInfo hWnd, True, True
Loop


Columns("A:C").EntireColumn.AutoFit
End Sub


Sonst habe ich jetzt keine weiteren Möglichkeiten.
Gruß Tino

Anzeige
AW: noch eine letzte Hilfestellung.
16.06.2009 10:11:54
chris
hallo Tino,
also das ist schon super viel was ich von dir bekommen haben.
Mit dem letzten code der eigentlich alle fenster listen soll werden mir diese SAP fenster nicht mit angezeigt.
Und das verstehe ich nicht.
Was kann oder muss ich tun ?
ich meine das Makro von Dir:
Sub vList_Prozesse()
Vielen dank
AW: noch eine letzte Hilfestellung.
16.06.2009 10:18:52
Tino
Hallo,
stelle mal in den zwei Zeilen GetWindowInfo hWnd, True, True
alles auf False und führen den Code nochmal aus.
Gruß Tino
AW: noch eine letzte Hilfestellung.
16.06.2009 10:21:27
chris
Super klappt tino.
ich glaube ich bekomme es nun hin.
Vielen Vielen Dank Tino und noch einen schönen Tag !!!!
gruß Chris
Anzeige
AW: noch eine letzte Hilfestellung.
16.06.2009 12:23:17
chris
Hallo Tino,
jetzt habe ich noch eine frage.
Du hast mir ja bis jetzt wirklich super geholfen.
Dafür noch einmal Danke.
Aber wie kann es jetzt sein das mir in diesen zeilen ein fenster gefunden wird sprich das Makro versucht ein fenster zu öffnen das ich schon mit x geschlossen habe ?
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
bleibt ein Fenstername vielleicht noch im Zwischenspeicher von Windows ? Wie lösche bzw. aktualisiere ich diesen ?
Noch einmal Dankeschön
Anzeige
da kann ich nur raten
16.06.2009 12:47:08
Tino
Hallo,
liegt wohl an Deinem Programm, dass irgendwelche Prozesse am Laufen hält,
normalerweise findest Du alle laufenden Prozesse im Taskmanager unter Prozesse.
Aber dazu kann ich wenig sagen, kenne Deine Anwendung und Dein System nicht.
Es gibt einige Prozesse die den gleichen Titel verwenden, z. Bsp. Excel in einer zweiten Instanz und schon hast Du zwei mit dem gleichen Titel.
Bei Dir wird es ähnlich sein, nur dass der eine Prozess sichtbar als Fester und der andere unsichtbar ist.
Möglichkeit den Prozess über Taskmanager Killen.
Gruß Tino
in Auflistung stimmt was nicht.
16.06.2009 12:58:42
Tino
Hallo,
bei der Auflistung hat im Code noch was nicht richtig gepasst.
Kommt davon wenn man einen Code der für was anderes gedacht ist auf die schnelle umstrickt.
Option Explicit

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 GetWindowText Lib "user32" _
        Alias "GetWindowTextA" _
        (ByVal hWnd As Long, ByVal lpString As String, _
        ByVal cch 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 GetWindowTextLength Lib "user32" _
        Alias "GetWindowTextLengthA" (ByVal hWnd As Long) _
        As Long

Private Declare Function GetWindowThreadProcessId Lib "user32" _
        (ByVal hWnd As Long, lpdwProcessId 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 GetParent Lib "user32" (ByVal hWnd _
        As Long) As Long
        
        
Const GW_HWNDFIRST = 0
Const GW_HWNDLAST = 1
Const GW_HWNDNEXT = 2
Const GW_HWNDPREV = 3
Const GW_OWNER = 4
Const GW_CHILD = 5
Const GW_MAX = 5

Const GWL_STYLE = (-16)

Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000

Dim LRow As Long
Private Sub GetWindowInfo(ByVal hWnd&, bVisible As Boolean, booMit_Titel As Boolean)
  Dim Task&, Result&, X&, Style&, Title$
  
    'Darstellung des Fensters 
    Style = GetWindowLong(hWnd, GWL_STYLE)
    Style = Style And (WS_VISIBLE Or WS_BORDER)

    Result = GetWindowTextLength(hWnd) + 1
    Title = Space$(Result)
    Result = GetWindowText(hWnd, Title, Result)
    Title = Left$(Title, Len(Title) - 1)
    
   If (Style = (WS_VISIBLE Or WS_BORDER)) Or bVisible = False Then
     
     If Title <> "" Or booMit_Titel = False Then
      LRow = LRow + 1
      Cells(LRow, 1) = CStr(hWnd)
      Cells(LRow, 2) = Title
      

      'Task Id ermitteln 
      Result = GetWindowThreadProcessId(hWnd, Task)
      Cells(LRow, 3) = Task
     
     End If
  End If
End Sub
Sub vList_Prozesse()
Dim hWnd As Long, tbuf As String, RetVal As Long


'Zellen leeren und Überschrift 
Cells.Clear
Range("A1") = "hwnd"
Range("B1") = "Titel"
Range("C1") = "Prozess ID"
Range("A1:C1").Font.Bold = True
LRow = 1
'______________________________
  
'hwnd Deskdopt 
  hWnd = GetDesktopWindow()
  hWnd = GetWindow(hWnd, GW_CHILD)
'hwnd, nur Sichtbar, nur Mit Fenstertitel 
  GetWindowInfo hWnd, False, False

Do While hWnd <> 0
    tbuf = String(255, 0)
    RetVal = GetWindowText(hWnd, tbuf, Len(tbuf))
    hWnd = GetWindow(hWnd, GW_HWNDNEXT)
    'hwnd, nur Sichtbar, nur mit Fenstertitel 
    GetWindowInfo hWnd, False, False
Loop


Columns("A:C").EntireColumn.AutoFit
End Sub


Gruß Tino

Anzeige
AW: in Auflistung stimmt was nicht.
16.06.2009 13:06:36
chris
Viele dank für die Korrektur !!

14 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige