Servus Wolfgang,
Code sollte funzen.
In deinen Code einbauen (Fenstercaption anpassen!!!!)
Dim xhWnd As Long
'Anwendung soll nur einmal gestartet werden, sonst bereits laufende Instanz in aktivieren
If App.PrevInstance Then
Me.Caption = "Cad Dateisuche (wird gestartet)" 'anderer Titel damit von Fenstersuche nichts gefunden wird
xhWnd = FindWindow(vbNullString, "Cad Dateisuche") 'Fenster suchen
Call ActivateWindow(xhWnd) 'Fenster aktivieren
End 'Diese Instanz killen
Else
Me.Caption = "Cad Dateisuche" 'Titel richtig stellen damit Fenster von nächster Instanz gefunden werden kann
End If
und die APIs dazu
'wird benötigt damit bereits laufende Instanz aktiviert werden kann
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName _
As String, ByVal lpWindowName As String) _
As Long
Private Declare Function GetWindowPlacement Lib _
"user32" (ByVal hWnd As Long, lpwndpl As _
WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib _
"user32" (ByVal hWnd As Long, lpwndpl _
As WINDOWPLACEMENT) As Long
Private Declare Function SetForegroundWindow Lib _
"user32" (ByVal hWnd As Long) As Long
Private Declare Function BringWindowToTop Lib _
"user32" (ByVal hWnd As Long) As Long
Const SW_SHOWNORMAL = 1
Const SW_SHOWMINIMIZED = 2
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Sub ActivateWindow(xhWnd As Long)
Dim Result As Long
Dim WndPlcmt As WINDOWPLACEMENT
With WndPlcmt
.Length = Len(WndPlcmt)
Result = GetWindowPlacement(xhWnd, WndPlcmt)
If Result Then
If .showCmd = SW_SHOWMINIMIZED Then
.flags = 0
.showCmd = SW_SHOWNORMAL
Result = SetWindowPlacement(xhWnd, WndPlcmt)
Else
Call SetForegroundWindow(xhWnd)
Result = BringWindowToTop(xhWnd)
End If
End If
End With
End Sub
Jürgen
------------------
54* SEV15SR8, 4*SEV16.00.01.03
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP