Forum: VB.NET |
Thema:
Re: Versionierung mit .Net & Verhinderung des Laufens mehrerer Instanzen eines Programms |
Von:
Stephan (
11.05.2005 15:34) |
Hier ein kleines Beispiel zu Punkt 2:
<DllImport("user32.dll")> Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As Boolean
End Function
<DllImport("user32.dll")> Private Shared Function ShowWindowAsync(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function
<DllImport("user32.dll")> Private Shared Function IsIconic(ByVal hWnd As IntPtr) As Boolean
End Function
Dim bExists As Boolean = False
Dim proc As String = Process.GetCurrentProcess.ProcessName
Dim processes As Process() = Process.GetProcessesByName(proc)
If processes.Length > 1 Then
Dim p As Process = Process.GetCurrentProcess
Dim n As Integer = 0
bExists = True
If processes(0).Id = p.Id Then
n = 1
End If
Dim hWnd As IntPtr = processes(n).MainWindowHandle
If IsIconic(hWnd) Then
ShowWindowAsync(hWnd, SW_RESTORE)
End If
SetForegroundWindow(hWnd)
End If
Return bExists
Ich habe dies in einer Funktion verwendet, darum auch der Return Wert.
LG
Stephan
Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!