XP Focus Bug with Full Screen

BlitzMax Forums/BlitzMax Programming/XP Focus Bug with Full Screen

Grey Alien(Posted 2009) [#1]
Please compile and run this on XP:

SuperStrict

Graphics 800,600,32

While Not KeyHit(key_escape)
	Cls
	DrawRect 100,100,100,100
	Flip 1
Wend


Then Alt+Tab out. Make sure you have some other apps running. Then use the tabs on the start bar to switch between apps. Noticed how the compiled app's window keeps flashing as you switch between apps. It seems like Windows XP is trying to focus the full-screen app temporarily but then focus is returned to the app that you clicked.

This is weird, any idea why it would do it? Perhaps full-screen apps are treated as modal and try to come to the front just in that split second between defocusing one app and focusing the next?

It doesn't happen in Vista.

It's causing a problem for me because I track EVENT_APPRESUME and EVENT_APPSUSPEND and do stuff like start and stop music. This means as you change apps you keep hearing a slit second of the music as it resumes and suspends due receiving focus for a split second.

Also sometimes with my current game (but not with the example above) my whole game does completely resume full-screen even though another totally different app was clicked! I don't know why as I don't have any code to tell it to do that, I'm just relying on BlitzMax (or Windows) to handle the focusing for me. Also sometimes the game nearly focuses but doesn't and the music resumes permanently because the app never got the suspend message. It's crazy and random seeming...

Anyone got any comments about this? Thx.


Arowx(Posted 2009) [#2]
As a workaround you could place a short delay in the code to prevent any hiccups.

Sorry don't have XP to test this on!


jsp(Posted 2009) [#3]
Confirmed, it flashes always when changing the focus.


Grey Alien(Posted 2009) [#4]
Thanks jsp.

@Merx: Yeah I considered having a delay before resuming music so I can double check if focus was REALLY returned to the game. The problem is that sometimes focus does return fully even though it should not have! It's very weird...


TaskMaster(Posted 2009) [#5]
Just have the game Pause when focus is lost and only resume on a keypress or mouseclick.

I have played other games and I like it that way. I don't want the game to just come up running if it has any sort of action. I want to prepare myself, see what is on the screen, get my hands where I need them, think about what button I want to press the instant the action starts, etc.


Grey Alien(Posted 2009) [#6]
Yeah actually I do that now in full-screen mode, so you won't here the music restarting and stopping, but the fact remains that the window still flickers and sometimes it randomly goes back to full-screen even though you clicked some other app on the task bar.


MGE(Posted 2009) [#7]
I don't experience any flickering on 2 XP systems here. But at the least I would never have a loop like that either. I always check for AppSuspended() before doing any rendering.

Does this code still flicker (on those systems that flicker) like the original when alt tab'ed?

SuperStrict
Graphics 800,600,32
While Not KeyHit(key_escape)
 If AppSuspended()
  While AppSuspended()
   Delay(100)
  Wend  
 EndIf
 Cls
 DrawRect 100,100,100,100
 Flip 1
 '
Wend



Grey Alien(Posted 2009) [#8]
I've now seen the same thing on non-Blitz max games like Turbo Pizza, so it's some kind of XP issue. Also I found a link to a hotfix for it.

Also found out the reason my game was resuming was a single line that compared GetForegroundWindow() (which is a win api function: http://msdn.microsoft.com/en-us/library/ms633505(VS.85).aspx ) with the Window Handle. When that line is in the game totally resumes instead of flickers and when it's out it just flickers. How weird is that? That function only returns a handle it doesn't do anything else...


jsp(Posted 2009) [#9]
@MGE
Your code 'flickers' the same as Greys on my system (XP Prof. SP2). I don't think the AppSuspended is even called at that time.


That function only returns a handle it doesn't do anything else...


Wild guess?:)


MGE(Posted 2009) [#10]
@jsp. Thanks! wow... talk about learning something new.