GetActiveWindow (user32)
Last changed: sim2kid-174.69.1.142

.
Summary

C# Signature:

[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();

VB.NET Signature:

<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function GetActiveWindow() As IntPtr
End Function

VB Signature:

Public Declare Function GetActiveWindow Lib "user32.dll" () As Long

User-Defined Types:

None.

Notes:

GetActiveWindow() will only return if the calling thread is in focus.

Tips & Tricks:

Can be used to find the active window Hwnd for GetWindowText

Sample Code:

Inside a Windows Form:

if (GetActiveWindow() == Handle) {
    // The Form is the active window
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation