DirectX and Window Focus
Hi, im not sure if i should post this in here or the Windows section.
If its in the wrong place could a mod please move it, thanks.
Im making myself a game and everythings going fine.
Its a windowed game set to maximized.
I was getting crashes when focusing onto another app while my game was still running. So i had a search about and found out about the WM_KILLFOCUS and WM_SETFOCUS messages sent when your app gets, or loses focus. So that has stopped the crashing!
If i switch to another app thats not maximized and move it around over the top of my game, the game isn't being drawn anymore so the screen gets all messed up.
Is there a certain message that windows sends to say the focus is lost COMPLETELY? So i can still draw my game if its still seen, but not in focus.
Hope that makes sense.
Things you lose in lost device conditions:
HRESULT hr = pDevice->TestCooperativeLevel();
if (hr == D3D_OK)
else if (hr == D3DERR_DEVICELOST)
else if (hr == D3DERR_DEVICENOTRESET)
- ID3DXFont - you must call it's On[Lost/Reset]Device functions.
- All resources using the D3DPOOL_DEFAULT memory pool. These must be recreated. Render target textures fall into this category since they must use D3DPOOL_DEFAULT. But this applies to all resources in Direct3D
- All IDirect3DStateBlock(s) will be released by the device (no need to call release()). These must be-recreated inside of OnResetDevice().
- ID3DXEffect(s) - must call their associated On[Lost/Reset]Device functions
- DirectInput keyboard - May have to re-acquire the keyboard
- If you are using CD3DFont you must call it's associated On[Lost/ResetDevice] functions
- Any swap chains created with CreateAdditionalSwapChain()
If most of your resources use D3DPOOL_MANAGED (which they should) it's not that difficult to put into your system. As an example my system can both respond to a lost device and come back as well as switch from windowed mode to full-screen mode and back on the fly.
Thanks very much Bubba!
That will be easy to implement into my game, i'll have a go and report back.
Now i've removed the WM_KILLFOCUS, WM_SETFOCUS code and used what you recommended.
The game now renders underneath other windows fine!
But now, when i completely switch windows (my game isnt seen at all) i get the crash again... It sometimes reboots my computer, and sometimes the gfx driver crashes and goes to low res/color depth.
I was reading the KILLFOCUS/SETFOCUS on msdn and thats a keyboard focus.
Is there anyway to tell if the Window is not in focus but still seen? (so i don't render)
EDIT: Found an error in debug log that i missed. After calling TestCooperativeLevel()