15

I have a self-made fullscreen application for Windows 7 written in C++ which should run for a long time on its own as a public presentation.

Problem is, there are several applications or drivers or Windows itself that steal focus from time to time and/or especially at system startup. Result is: My fullscreen application gets minimimized.

It is very annoying and nearly impossible to always find out which things you have to deactivate to prevent that. Especially because those focus stealing things are sometimes needed, e.g. touchscreen drivers.

What can I do to prevent losing focus?

Or even better: How can I prevent other applications from stealing focus - I remember there once was such a setting in TweakUI for Windows XP.

Martin B
  • 23,670
  • 6
  • 53
  • 72
Ole Dittmann
  • 1,764
  • 1
  • 14
  • 22

1 Answers1

21

Tweak UI does it by changing the SPI_SETFOREGROUNDLOCKTIMEOUT. You can combine this with LockSetForegroundWindow.

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
  • 1
    A good answer, but unfortunately it does not solve my problem. I presume the problem is not an application trying to set an already existing window to the forground which is prevented by default in windows 7 I guess. But it is something that creates a temporary window via shellexec or something. Some evil scheduled background process from a driver or auto updater or whatever. Bad thing is that I do not have easy access to the player computer :-( – Ole Dittmann Sep 15 '11 at 14:06
  • 3
    LockSetForegroundWindow should block that scenario. Note however that the lock you set via LockSetForegroundWindow is cleared when the user presses Alt or clicks on another window, so you have to keep an eye on it. – Raymond Chen Sep 15 '11 at 14:51
  • Your solution works. Made a mistake with SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT...) because I did not realize that you have to pass the value via the pointer parameter value although there is an integer parameter (Which is weird, of course) – Ole Dittmann Sep 15 '11 at 22:12
  • 1
    It sounds like a bad idea for an app to set a global system parameter (SPI_SETFOREGROUNDLOCKTIMEOUT) to solve a local problem of losing focus. Or am I wrong about that? – Gabe Oct 04 '11 at 05:23
  • 4
    In general, yes, but this program is running on a machine dedicated to running just that one application, so global = local in this case. – Raymond Chen Oct 04 '11 at 06:28