Home
Products
Community
Manuals
Contact
Login or Signup

GetActiveWindow() for fullscreen 3D mode.

Blitz3D Forums/Blitz3D Bug Reports/GetActiveWindow() for fullscreen 3D mode.

@rtur(Posted 1+ years ago) #1
There is GetActiveWindow() WinAPI function that return window hWND that is currently in focus. But this function does not work in fullscreen mode. This is a problem.

I know that I can use GetAsyncKeyState%(vKey) WinAPI function to catch ALT+Tab and other keypresses and pause my game, disable music, sounds etc.
But the game can be interrupted by system messages or something else. So analog of GetActiveWindow() for fullscreen is very neccesary to write commercial games.

Can you, please, add this sort of functionality to Blitz3D ?

So we can easily know if game is lost focus or minimased, or interrupted (etc) and set it to pause.


Sorry for my bad english.
BTW,this is request from all Russian comunity :)


TomToad(Posted 1+ years ago) #2
Did you try this?
http://www.blitzbasic.com/codearcs/codearcs.php?code=853


@rtur(Posted 1+ years ago) #3
Of course! It does not work in fullscreen mode.


@rtur(Posted 1+ years ago) #4
I know that I can check time passed since last render, to catch moment when user got focus back after losing it during some time.(I've done this in Master of Defense)

But I need to disable music/sounds, freeze timers etc, so I need to know when user lost focus, not when he is recieved it back.

I hope you understood what I'm saying :)


@rtur(Posted 1+ years ago) #5
I've also tryied to catch windows message WM_ACTIVATE.
But Blitz3D suspend code execution when focus lost, and I'm recieving this message only when game recieve focus and execution continues.


@rtur(Posted 1+ years ago) #6
If we will be able to recieve this message before Blitz, do all we need(pause sounds and game etc), and then send this message to Blitz- this will be solution of the problem, I think.


@rtur(Posted 1+ years ago) #7
Here is a little example, so you can test this bug:

Graphics3D 800,600,32,1; <- try to switch to window/fullscreen mode 

hWND=SystemProperty("AppHWND")

GlobalTimer=vdCreateTimer()



While Not KeyDown(1)

ActiveWindow=api_GetActiveWindow()
If ActiveWindow<>hWND 
	MainLoopPaused=True
	vdSetAllTimersPause(True)
	Delay 1
Else
	If OldActiveWindow<>hWND
		vdUpdateTimers()

		vdSetAllTimersPause(False)
		MainLoopPaused=False
	EndIf
EndIf
OldActiveWindow=ActiveWindow

	If MainLoopPaused=False
		;Main loop goes here
		vdUpdateTimers()
		UpdateWorld()
		RenderWorld()
		Cls
		Text 10,10,vdGetTimer(GlobalTimer)

		Flip
	EndIf			
Wend

End









Const cTimeTimer=1

Type TimerT
    Field TimerID
    Field TimerTime
    Field TimerFrame
    Field StartTime
    Field CurTime
    Field Paused
    
End Type

Function vdCreateTimer()
	
	this.TimerT		= New TimerT           
	this\TimerID	= Handle(this.TimerT) 
	this\StartTime  = MilliSecs()
	this\CurTime  	= 0
	this\TimerTime	= 0     
	this\Paused		= False
	
	
	Return this\TimerID                       
	
End Function

Function vdGetTimer(TimerID,TypeOfTimer=cTimeTimer)
	
	this.TimerT = Object.TimerT(TimerID)
	
	Return this\TimerTime
	
End Function

Function vdSetAllTimersPause(Pause)
	
	For this.TimerT=Each TimerT
		this\Paused=Pause
	Next
	
End Function


Function vdUpdateTimers()
	Local TimeDiff,NewCurTime
	
	For this.TimerT=Each TimerT
		
		NewCurTime=MilliSecs()-this\StartTime
		TimeDiff=NewCurTime-this\CurTime
		this\CurTime=NewCurTime
		
		If this\Paused=False
			this\TimerTime=this\TimerTime+TimeDiff 
		EndIf
	Next
	
End Function