Platform SDK: Windows User Interface

AllowSetForegroundWindow

The AllowSetForegroundWindow function 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.

BOOL AllowSetForegroundWindow(
  DWORD dwProcessId   // process identifier
);

Parameters

dwProcessId
[in] Specifies the identifier of the process that will be enabled to set the foreground window. If this parameter is ASFW_ANY, all processes will be enabled to set the foreground window.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. The function will fail if the calling process cannot set the foreground window. To get extended error information, call GetLastError.

Remarks

Starting with Windows 98 and Windows 2000, 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:

A process that can set the foreground window can enable another process to set the foreground window by calling AllowSetForegroundWindow. The process specified by dwProcessId loses the ability to set the foreground window the next time the user generates input, unless the input is directed at that process, or the next time a process calls AllowSetForegroundWindow, unless that process is specified.

Windows 98: This function is not implemented on Windows 98. Therefore, processes must cooperate to manage the foreground window. For example, an application may wish to support only one instance. When the second instance starts up, it should detect the previous instance and call SetForegroundWindow on the window of the previous instance. It should not post a message to the window of the previous instance asking it to call SetForegroundWindow on itself, because the previous instance will not necessarily have permission to call SetForegroundWindow.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Unsupported.
  Header: Declared in Winuser.h; include Windows.h.
  Library: Use User32.lib.

See Also

Windows Overview, Window Functions, LockSetForegroundWindow, SetForegroundWindow