SetForegroundWindow (user32)
Last changed: -81.5.16.253

.
Summary

C# Signature:

[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);

VB Signature:

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As IntPtr) As Long

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

Public Sub RaiseOtherProcess()

Dim proc As Process = Process.GetCurrentProcess()

Dim assemblyName As String = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name

For Each otherProc As Process In Process.GetProcessesByName(AssemblyName)

    If Not (proc.Id = otherProc.Id) Then
    Dim hWnd As IntPtr = otherProc.MainWindowHandle
    If IsIconic(hWnd) Then
        ShowWindowAsync(hWnd, SW_RESTORE)
    End If
    SetForegroundWindow(hWnd)
    Return
    End If

Next

End Sub

Alternative Managed API:

Do you know one? Please contribute it!

Documentation