Archived

This topic is now archived and is closed to further replies.

mdfmKoRn

Atl+Tab Direct 3d anomaly

Recommended Posts

I can''t get my game to stop acting weird when I alt+tab out of it. Here''s what I put in the Windows message pump to stop it:
  
case WM_ACTIVATE:
{
    WinActive=LOWORD(wParam)!=WA_INACTIVE;
    if ( WinActive==false )
	DeInit();
    else
        InitD3D( hWnd );
    return 0;
}
  
DeInit() looks like this:
  
VOID DeInit()
{
    if( pD3DDevice != NULL) 
        pD3DDevice->Release();

    if( pD3D != NULL)
        pD3D->Release();
}
  
I can alt+tab out, but if I click on a few other windows, my game regains the focus on its own and proceeds to draw without responding to the mouse or keyboard. Anybody know what''s going on? How do I make my game Alt+Tab friendly? ---- Herb M. (mdfmKoRn) www.sky-meyg.com s3202@attbi.com

Share this post


Link to post
Share on other sites
A good method I''ve found is to use TestCooperativeLevel method of the IDirect3DDevice8 interface...so JUST before you call BeginScene in your rendering loop, you test the cooperative level...if you get back a D3DERR_DEVICEERR (or something like that..check the docs) then the user has alt+tabbed out of your program.

You''ll have to call Reset to rest the device, then (depending on how you declared your vertex buffers), you''ll have to reload the vertex and texture information...

ie.
  
HRESULT beginRendering()
{
HRESULT hr;
hr = lpD3DDevice->TestCooperativeLevel();
if(FAILED(hr))
(
if(hr == D3DERR_DEVICEERR)
{
//reset the direct3d device, and reload the

//textures

lpD3DDevice->Reset();
hr = loadTextures();
if(FAILED(hr))
{
return E_FAIL;
}

}
}

lpD3DDevice->Clear(..);
return(lpD3DDevice->BeginScene());
}

something like that..

Share this post


Link to post
Share on other sites
You have to check for windows messages when application loses focus. Stop all rendering when this happends. Resume rendering when your application receives focus (you''ll probably have to Reset the device, due to D3DERR_DEVICELOST).

Share this post


Link to post
Share on other sites