Handling Alt-Tab in fullscreen app

Started by
0 comments, last by Headkaze 16 years, 10 months ago
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]
--"I'm not at home right now, but" = lights on, but no ones home
Advertisement
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;	}}

This topic is closed to new replies.

Advertisement