Sign in to follow this  
nguyen my

lost device in directx

Recommended Posts

i have a program by vc++ with direct9x. this is program about drawing primitive cube and rotation around y-axis. but when i press Alt+Tab it is lost , don't rotation around y-axis. this source code of program. please everyone help me
http://www.mediafire.com/file/kfz96w188yfe35d/c72.rar

Share this post


Link to post
Share on other sites
For future reference, try to explain your problems more thoroughly and show relevant code.

You were not re-acquiring input from your DirectInput devices when your window was restored. I added the following:

Make a method in DXINPUT called reclaim() and use this:

void DXINPUT::reclaim()
{
if ( !keyboard || !mouse ) return;

HRESULT hr = keyboard->GetDeviceState( sizeof(keys), keys );

if (FAILED(hr))
{
// If input is lost then acquire and keep trying until we get it back
hr=keyboard->Acquire();
while( hr == DIERR_INPUTLOST )
{
hr = keyboard->Acquire();
}
// Could be we failed for some other reason
if (FAILED(hr))
return;
// Now read the state again
keyboard->GetDeviceState( sizeof(keys), keys );
}



hr = mouse->GetDeviceState( sizeof(mouse_state), &mouse_state );

if (FAILED(hr))
{
// If input is lost then acquire and keep trying until we get it back
hr=mouse->Acquire();
while( hr == DIERR_INPUTLOST )
{
hr = mouse->Acquire();
}
// Could be we failed for some other reason
if (FAILED(hr))
return;
// Now read the state again
mouse->GetDeviceState( sizeof(mouse_state), &mouse_state );
}

}


Next, go to main.cpp and change your WM_ACTIVATE event to this:

case WM_ACTIVATE:
if(wparam==WA_INACTIVE)
paused=true;

else if(wparam==WA_ACTIVE)
{
paused=false;

// Reclaim input
if ( dinput ) dinput->reclaim();
}

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