Is it possible to prevent an application from being activated (brought to front) without using DLL injection?

StackOverflow https://stackoverflow.com/questions/16543651

  •  29-05-2022
  •  | 
  •  

Question

I need to write application A, which intercepts the WM_ACTIVATE message to a window of application B in order to prevent B from becoming top-most application.

Is it possible to do this without DLL injection (add a hook on that message, process and "neutralize" it with a series of WinAPI calls) ?

Was it helpful?

Solution

I think this is what you're after:

LockSetForegroundWindow

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633532(v=vs.85).aspx

Remarks The system automatically enables calls to SetForegroundWindow if the user presses the ALT key or takes some action that causes the system itself to change the foreground window (for example, clicking a background window). This function is provided so applications can prevent other applications from making a foreground change that can interrupt its interaction with the user.

Just don't forget to unlock :)

Edit:

Try SetWinEventHook as described here:

Is there Windows system event on active window changed?

Then when the unwanted window comes to the front you can send it to the background.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top