The documentation is not good on this subject. I've noticed that with PB 4.30, the best way to use IsScreenActive() when your screen is no more active is to use WaitWindowEvent, even if you don't have a window. Prior to 4.30, you can't use WaitWindowEvent(), and it was failing all the time with flipbuffers() like said in the doc.
See my topic for an example : http://www.purebasic.fr/english/viewtopic.php?t=36852
IsScreenActive() doc
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Check this code without debugger (run it, ALT-Tab to desktop, and come back). Everything is OK. Then, try to change the waitwindowevent to a flipbuffers() or anything else and do the same test. It doesn't come back.
Code: Select all
;*****************************************************************************
;* Lost focus test
;* By djes (djes@free.fr) 05/27/2009
;*****************************************************************************
;*****************************************************************************
Procedure create_sprites()
CreateSprite(0, 64, 64)
StartDrawing(SpriteOutput(0))
Circle(32, 32, 31, RGB($FF, $FF, $FF))
StopDrawing()
EndProcedure
;*****************************************************************************
;Open screen
Procedure init_display()
OpenScreen(1024, 768, 32, "")
SetFrameRate(60)
SetRefreshRate(60)
EndProcedure
;*****************************************************************************
;Check if the user has switched (and that we have lost focus) (ALT-TAB)
;Vérifie si l'utilisateur n'a pas changé d'appli (en nous faisant donc perdre le focus) (ALT-TAB)
Procedure check_lostfocus()
If IsScreenActive() = 0
ReleaseMouse(1)
;Wait til our window is coming back to foreground - Attend que notre fenêtre repasse au premier plan
Repeat
;now our events are to be processed with WaitWindowEvent, else IsScreenActive() will never say that our window has the focus again
;it should be written in the doc!
;maintenant les événements sont à gérer avec WaitWindowEvent, sinon IsScreenActive() ne dit jamais que notre fenêtre a à nouveau le focus
;il faudrait mettre ça dans la doc!!!!
WaitWindowEvent()
Until IsScreenActive() <> 0
ReleaseMouse(0)
;Better recreate the screen - il vaut mieux recréer l'écran
CloseScreen()
init_display()
;and the sprites too (have to!) - et les sprites aussi (indispensable)
create_sprites()
;give to the system some time to rest - laisse un peu le temps au système de récupérer
Delay(2000)
EndIf
EndProcedure
;*****************************************************************************
;- START
;*****************************************************************************
InitSprite()
InitKeyboard()
InitMouse()
init_display()
create_sprites()
;*****************************************************************************
;- MAIN LOOP
;*****************************************************************************
exit=#False
Repeat
FlipBuffers(#PB_Screen_WaitSynchronization)
check_lostfocus()
ExamineKeyboard()
ExamineMouse()
If KeyboardPushed(#PB_Key_Escape)
exit=#True
EndIf
ClearScreen(0)
For i = 1 To 100
DisplaySprite(0, Random(1024), Random(768))
Next i
Until exit
CloseScreen()
End