detecting return from alt-tab

Archives Forums/BlitzPlus Programming/detecting return from alt-tab

keyboard(Posted 2006) [#1]
just messing around with detecting an alt-tab, then returning to a full-screen game. Is this the best method, I wonder? Comments welcome.

; Bad things happen when you change the window focus, depending how you are
; managing your graphics buffers
; If you could detect an Alt/Tab or WinKey hit, you could refresh
; your screen, or do whatever it takes to get everything in order!

Graphics 800,600
Global WindowFocusChanged=False;define a boolean to assign to the event of a window focus change
SetBuffer BackBuffer();set the buffer to be drawn to
While Not KeyHit(1);hit the Esc key to quit
ClsColor 0,0,0;set the ClearScreen Colour to black
Cls;clear the backbuffer of the previous display
If WaitEvent(0)=$2002 WindowFocusChanged=True;detect if the focus has returned to the game window
If KeyHit(46) WindowFocusChanged=False;the "C" key clears the screen
Color 204,0,153
Rect 200,180,400,50,1;draw a background for the text
If WindowFocusChanged;if we have "alt/tabbed" or similar
Color 51,153,0
Rect 200,280,400,50,1
Color 255,255,255;set the text colour to white
Text 400,300,"you Alt/Tabbed! >>>>>> C:cls",True,False;we have alt/tabbed
;here you can redraw the screen display, or whatever :)
Color 255,255,255;set the text colour to white
Text 400,200,"Alt/Tab then return here! >>>>>> Esc:quit",True,False;the screen instructions
Rect 0,0,800,600,0; decorative border
Flip;flip the backbuffer to the display buffer