C ++ - DirectX截屏在全屏游戏中不起作用

时间:2014-08-09 01:03:10

标签: c++ directx screenshot

我正在尝试使用DirectX在C ++中制作屏幕截图,它在桌面应用程序和桌面上也能很好地工作,但是当我在全屏播放游戏时我无法截屏,没有任何内容可以保存。 有人知道如何解决这个问题吗?

int D3DScreenshot(char* name)
{
    int ret;

    HWND hwnd = GetDesktopWindow();
    IDirect3DDevice9 *g_pd3dDevice;
    D3DPRESENT_PARAMETERS d3dpp;
    IDirect3D9 *g_pD3D = NULL;
    IDirect3DSurface9* pSurface;

    g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
    if (g_pD3D == NULL)
        return 0;

    ZeroMemory(&d3dpp, sizeof(d3dpp));

    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    d3dpp.BackBufferCount = 1;
    d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
    d3dpp.MultiSampleQuality = 0;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    d3dpp.hDeviceWindow = hwnd;
    d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
    d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;


    if ((ret = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice)) != D3D_OK)
        return 0;

    if ((ret = g_pd3dDevice->CreateOffscreenPlainSurface(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurface, NULL)) != D3D_OK)
        return 0;

    if ((ret = g_pd3dDevice->GetFrontBufferData(0, pSurface)) != D3D_OK)
        return 0;
    if (( ret = D3DXSaveSurfaceToFile(TEXT(name), D3DXIFF_JPG, pSurface, NULL, NULL)) != D3D_OK)
            return 0;
    g_pD3D->Release();
    pSurface->Release();

    return (0);
}

0 个答案:

没有答案