Losing Focus in a DirectX Project
I bet most people in this forum have came across this one before, when say you press Alt + Tab and your DirectX App loses focus it doesn't like it, yeah? Well I know you can Restore Surfaces then reload the images but does anyone know if theres a way just to stop it from losing the surfaces in the first place?
Thanx,
Paul
Re: Losing Focus in a DirectX Project
You can check for focus by using GetActiveWindow, a minor API call:
Code:
Public Declare Function GetActiveWindow Lib "user32" () As Long
If GetActiveWindow = Form1.hWnd Then
'You've got the focus
Else
'You've not
End If
Dunno about restoring surfaces though...? My program throws automation errors when it restores, but this method might work for you though, 'cos I'm not using many surfaces, mostly textures and sprites and stuff. (And because I'm hideously error-prone at times.) I presume your Form_Load sub holds all the surface-loading code, yeah? You can cheat: whenever the form reactivates, bomb it out and load it again.
The best way to go about that is just to use a little sub called Form_Activate and a variable saying when the program's tabbed out.
Code:
Private Sub Form_Load
'The lot
TabOut = False
End Sub
Private Sub Form_Activate
If TabOut = True Then
Unload Me 'Not sure if this is necessary
Form_Load
End If
End Sub
'Later on, in the main loop...
Private Sub RenderAll 'Called by the main loop
If GetActiveWindow = Me.hWnd Then
'Do the funky rendering gibbon
Else
TabOut = True
End If
End Sub
That any good for you?
Edit: You do know that [VBCode] thing [/VBCode] in your sig doesn't work, don't you?