Sign in to follow this  
AngleWyrm

Handling Alt-Tab in fullscreen app

Recommended Posts

I spent rather a lot of time searching for the answer to this question, and eventually had to generate my own blend of solution. It works, so this is how I did it:
void win_app::render_scene(float elapsed_seconds)
{
    if(dx.screen == NULL){
        return;
    }

    static HRESULT result;
    result = dx.screen->TestCooperativeLevel();
    switch(result){
        case D3D_OK:
            break;
        case D3DERR_DEVICELOST:
            return;
        case D3DERR_DEVICENOTRESET:
            dx.reset(main_window);
            return;
        case D3DERR_DRIVERINTERNALERROR:
            return;
    }
    // render code 
The dx.screen object is a LPDIRECT3DDEVICE9. Code in the dx.reset(HWND)
void d3d_class::reset(HWND window)
{
     screen->Reset(&screen_parameters);
};



Any comments? Anything I'm missing? [Edited by - AngleWyrm on June 8, 2007 2:53:03 PM]

Share this post


Link to post
Share on other sites
You might like to use CheckCooperativeLevel() instead rather than causing an exception by using TestCooperativeLevel(). Checking it instead gives a result code you can then test. I'm using MDX so I will post my code for it, but shouldn't be too hard to figure out.

protected void AttemptRecovery()
{
int ret;

m_device.CheckCooperativeLevel(out ret);

switch (ret)
{
case (int)ResultCode.DeviceLost:
break;
case (int)ResultCode.DeviceNotReset:
try
{
m_device.Reset(m_pp);
deviceLost = false;
}
catch (DeviceLostException)
{
System.Threading.Thread.Sleep(50);
}
break;
}
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this