Jalaj P. Jha Technical & Miscellaneous Ramblings

30Jan/070

WinAPI : Prevent Setting foreground window

The earliest Windows Operating Systems allowed any process to set the foreground window. However with Windows98/Me restriction were placed for which process should be allowed to set a foreground window. That may be the process itself in the foreground or a process started by it or the process that last received the input event. Any other process can set foreground window only if there is no other process in foreground or explicitly allowed using the AllowSetForegroundWindow function or no lock has been placed using LockSetForegroundWindow function. Windows98/Me allows setting a foreground lock timeout which if set to zero makes the operating system behave as with the earlier versions.

The LockSetForegroundWindow function disables other processes from setting the foreground window. The function takes a lockCode parameter which may be one of the constants as defined below. The function returns non-zero if it succeeds otherwise non-zero.

Declare Function LockSetForegroundWindow Lib "user32.dll" (ByVal uLockCode As Long) As Long

Const LSFW_LOCK = 1
Const LSFW_UNLOCK = 2

The AllowSetForegroundWindow function enables specified process, which it takes as parameter, to set foreground window. The function returns non-zero if it succeeds otherwise zero. If ASFW_ANY as defined below is passed for parameter all processes are allowed setting the foreground window.

Declare Function AllowSetForegroundWindow Lib "user32.dll" (ByVal dwProcessId As Long) As Long

Const ASFW_ANY = -1
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.

  • Twitter
  • Buzz
  • Facebook
  • Orkut
  • Picasa
  • YouTube