Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (2 posts)

Direct3D9 Capture Fullscreen Window

Last post 8/9/2014 6:03 PM by Charybdis. 1 replies.
  • 8/9/2014 4:53 PM

    Direct3D9 Capture Fullscreen Window

    Hello,

     

    I am a beginner C++ developer and I made a program that takes screenshots of games.

    The application works for when the game is windowed but fails when the game is fullscreen.

    I managed to isolate my code to a single .cpp file :

    #include "stdafx.h"
    #include <d3d9.h>
    #include <d3dx9.h>
    #include "DirectXTools.h"
    
    LPDIRECT3D9 directX;
    LPDIRECT3DDEVICE9 directXDevice;
    
    void initDevice(HWND myWindow);
    void ConvertCharToWC(char* src, wchar_t* target);
    
    void DirectXTools::CaptureWindow(const char* windowName)
    {
        Sleep(5000);
        HWND windowHandle = GetForegroundWindow();
        initDevice(windowHandle);
    }
    
    void initDevice(HWND myWindow) {
        D3DDISPLAYMODE  ddm;
        D3DPRESENT_PARAMETERS   d3dpp;
        IDirect3DSurface9* g_pSurface;
    
        if((directX=Direct3DCreate9(D3D_SDK_VERSION))==NULL)
        {
            throw "";
        }
    
        if(FAILED(directX->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&ddm)))
        {
            throw "";
        }
    
        ZeroMemory(&d3dpp,sizeof(D3DPRESENT_PARAMETERS));
    
        d3dpp.Windowed=FALSE;
        d3dpp.Flags=D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
        d3dpp.BackBufferFormat=ddm.Format;
        d3dpp.BackBufferHeight=ddm.Height;
        d3dpp.BackBufferWidth=ddm.Width;
        d3dpp.MultiSampleType=D3DMULTISAMPLE_NONE;
        //  d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
        d3dpp.SwapEffect=D3DSWAPEFFECT_COPY;
        d3dpp.hDeviceWindow=myWindow;
        d3dpp.PresentationInterval=D3DPRESENT_INTERVAL_DEFAULT;
        d3dpp.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT;
    
        if(FAILED(directX->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,myWindow,D3DCREATE_SOFTWARE_VERTEXPROCESSING ,&d3dpp,&directXDevice)))
        {
            throw "";
        }
    
        if(FAILED(directXDevice->CreateOffscreenPlainSurface(ddm.Width, ddm.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &g_pSurface, NULL)))
        {
            throw "";
        }
    
        directXDevice->GetFrontBufferData(0, g_pSurface);
        D3DXSaveSurfaceToFile("temp.bmp",D3DXIFF_BMP,g_pSurface,NULL,NULL);
    }

    The error occurs at the directX->CreateDevice function. it simply returns the error code D3DERR_DEVICELOST.

    To test it I am running program then open the game. (The 5000 ms sleep give me time to open the game)

    Anyone knows whats the problem with the code here?

  • 8/9/2014 6:03 PM In reply to

    Re: Direct3D9 Capture Fullscreen Window

    Direct3D 9 fullscreen is 'exclusive' which means only a single device be active at a given time. The game is clearly the fullscreen exclusive device.
Page 1 of 1 (2 posts) Previous Discussion Next Discussion