Jump to content
  • Advertisement
Sign in to follow this  
InsaneBoarder234

Handling Alt + Tab in Direct3D

This topic is 4828 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

In DirectDraw, if a program draws to the screen when its window isn't active (at least in fullscreen mode), the program crashes. To handle this all I had to do was handle the WM_ACTIVATE messages to check for the application window being activated and de-activated and allow/block drawing to the primary buffer as these events happened. Now moving over to Direct3D, I am porting a game I have wrote with DirectDraw over to Direct3D9, mainly to build up some knowledge of using Direct3D. I've wrote a class which manages Direct3D and the application window and I have done the same as I used to do with DirectDraw, which is shown below:
class CD3DDisplay
{
public:
    //...
    static void SetWindowActiveState(bool bActive)
    {
       m_WindowActive = bActive;
    }
    void RenderToScreen()
    {
        if(m_WindowActive == true)
            m_D3DDevice->Present(0, 0, 0, 0);
    }

private:
    //...
    static bool m_WindowActive;
};

//Window Procedure
switch(msg)
{
    //...
    case WM_ACTIVATE:
        if(LOWORD(wParam) == WA_INACTIVE)
        {
            CD3DDisplay::SetWindowActiveState(false);
        }
        else
        {
            CD3DDisplay::SetWindowActiveState(true);
        }
}


Now this might seem stupid but when I tested this code I alt + tabbed away from the window and then clicked on it in the taskbar to get it back up and it simply shows the window, it doesn't go back to the fullscreen display mode I set it up in. Upon further inspection I also noticed that m_3DDevice->Present() returns D3DERR_DEVICELOST. Can anyone help a newbie out and give me an idea of how I am supposed to handle the WM_ACTIVATE messages with Direct3D? Thank you very much in advance!

Share this post


Link to post
Share on other sites
Advertisement
You need to reset (IDirect3DDevice9::Reset()) your device, then re-create all of the resources created in the D3DPOOL_DEFAULT area.

I can never remember the exact lines of code behind it - I wrote this stuff once and haven't needed to touch it again [smile]

The SDK framework is the best resource for this, the code is an excellent reference as to the "text book" way of handling these sorts of events. The code's quite big/complex, but it's not too difficult to follow around.

hth
Jack

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!