Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
AllowSetForegroundWindow (user32)
Enables the specified process to set the foreground window using the SetForegroundWindow function. The calling process must already be able to set the foreground window. For more information, see Remarks later in this topic.

C# Signature:

static extern bool AllowSetForegroundWindow(int dwProcessId);

VB.Net Signature:

<DllImport("user32.dll")> _
Shared Function AllowSetForegroundWindow(ByVal dwProcessId As Integer) As Boolean
End Function

User-Defined Types:




Tips & Tricks:

ASFW_ANY = -1 // by MSDN

Sample Code:


Alternative Managed API:

Do you know one? Please contribute it!


The system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true:

- The process is the foreground process.

- The process was started by the foreground process.

- The process received the last input event.

- There is no foreground process.

- The foreground process is being debugged.

- The foreground is not locked (see LockSetForegroundWindow).

- The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).

- No menus are active.


Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version