Live-Forum - Die aktuellen Beiträge
Datum
Titel
28.03.2024 21:12:36
28.03.2024 18:31:49
Anzeige
Archiv - Navigation
1096to1100
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

AppActivate -> dann Fenster in Vordergrund

AppActivate -> dann Fenster in Vordergrund
marspoki
Hallo,
ich muß mit VBA ein andere Anwendung aktivieren und in den vordergrund holen. wenn möglich so, dass sich die ursprüngliche Fesntergröße nicht ändert.
Aktivieren tue ich das so:
AppActivate ("Programmname")
Aber manchmal bleibt das fenster dann minimiert.
Kann man da was machen?
VIele Grüße
Sebastian
AW: AppActivate -> dann Fenster in Vordergrund
14.08.2009 15:37:52
Eberhard
Hallo Sebastian
vielleicht hilft dir folgender Code
Sub etitor()
Dim TaskID As Long
'vbHide   0   Das Fenster ist ausgeblendet, und das
'ausgeblendeteFenster erhält den Fokus.
'vbNormalFocus   1 Das Fenster hat den Fokus, und die ursprüngliche
'Größe und Position wird wiederhergestellt.
'vbMinimizedFocus   2   Das Fenster wird als Symbol mit Fokus angezeigt.
'vbMaximizedFocus   3   Das Fenster wird maximiert mit Fokus angezeigt.
'vbNormalNoFocus 4   Die zuletzt verwendete Größe und Position des Fensters wird
'wiederhergestellt. Das momentan aktive Fenster bleibt aktiv.
'vbMinimizedNoFocus     6   Das Fenster wird als Symbol angezeigt.
'Das momentan aktiveFenster bleibt aktiv.
TaskID = Shell("notepad.exe", vbMaximizedFocus)
AppActivate TaskID
End Sub

Gruß
Eberhard
Anzeige
AW: AppActivate -> dann Fenster in Vordergrund
14.08.2009 15:50:03
marspoki
Ok das Funktioniert mit einer "exe" wunderbar.
ich müsste aber den Fenstertitel ansprechen können.
Vielen Dank Sebastian
AW: AppActivate -> dann Fenster in Vordergrund
14.08.2009 16:27:52
Eberhard
Hallo Sebastian
Da fällt mit nur die folgende API-Lösung ein

Option Explicit
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName _
As String, ByVal lpWindowName As String) _
As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String) As Long
Private Sub editor()
Dim TaskID As Long
Dim xhWnd&
TaskID = Shell("notepad.exe", vbMaximizedFocus)
AppActivate TaskID
xhWnd = FindWindow(vbNullString, "Unbenannt - Editor")
SetWindowText xhWnd, "Neuer Titel"
End Sub
Gruß
Eberhard

Anzeige
AW: AppActivate -> dann Fenster in Vordergrund
14.08.2009 16:46:47
marspoki
Das funktioniert leider gar nicht. Hat noch jeamand eine Idee?
AW: AppActivate -> dann Fenster in Vordergrund
14.08.2009 17:46:48
Nepumuk
Hallo,
versuch es mal so:
Option Explicit

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32.dll" ( _
    ByVal hwnd As Long) As Long

Public Sub test()
    Dim lngHwnd As Long
    lngHwnd = FindWindow(vbNullString, "Microsoft Office InfoPath 2003")
    If lngHwnd <> 0 Then Call SetForegroundWindow(lngHwnd)
End Sub

Gruß
Nepumuk
Anzeige
AW: AppActivate -> dann Fenster in Vordergrund
14.08.2009 18:16:42
marspoki

Hallo,
versuch es mal so:
Option Explicit
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32.dll" ( _
ByVal hwnd As Long) As Long
Public Sub test()
Dim lngHwnd As Long
lngHwnd = FindWindow(vbNullString, "Microsoft Office InfoPath 2003")
If lngHwnd  0 Then Call SetForegroundWindow(lngHwnd)
End Sub
Gruß
Nepumuk

Mein Programm ist minimiert in der Taskleiste. Ich muß das Fenster wieder öffnen und dann soll es den Fokus erhalten.
Diese funktion gelt leider nur wenn das Programm nicht Minimiert ist.
Vielen Dank Trotzdem
Sebastian
Anzeige
AW: AppActivate -> dann Fenster in Vordergrund
14.08.2009 19:24:04
Nepumuk
Hi,
so?
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32.dll" ( _
    ByVal hwnd As Long, _
    ByVal nCmdShow As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32.dll" ( _
    ByVal hwnd As Long) As Long

Private Const SW_NORMAL As Long = 1

Public Sub test()
    Dim lngHwnd As Long
    lngHwnd = FindWindow(vbNullString, "Microsoft Visio")
    If lngHwnd <> 0 Then
        Call ShowWindow(lngHwnd, SW_NORMAL)
        Call SetForegroundWindow(lngHwnd)
    End If
End Sub

Gruß
Nepumuk
Anzeige
AW: AppActivate -> dann Fenster in Vordergrund
14.08.2009 19:40:10
marspoki
gut das funktioniert.
Nur noch eins?
gibt es auch eine Möglichkeit wenn ich nur die ersten 5 Zeichen des Fensternamen kenne?
VG
Sebastian
AW: AppActivate -> dann Fenster in Vordergrund
14.08.2009 19:48:06
Nepumuk
Hallo,
dann schau mal Tinos Vorschlag an.
Gruß
Nepumuk
versuche es mal hiermit...
14.08.2009 19:17:04
Tino
Hallo,
, bei STitel den Titel angeben. (einen Teil davon)
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 = "Herbers"

  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

82 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige