Jump to content
  • Advertisement
Sign in to follow this  
nguyen my

lost device in directx

This topic is 2813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!