Jump to content

  • Log In with Google      Sign In   
  • Create Account

Screenshot of game window


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 aramcpp   Members   -  Reputation: 105

Like
0Likes
Like

Posted 31 July 2013 - 01:07 AM

How can i take a screenshot of a full screen game in c++? I know it can be done with directx and i have written a simple code which can take a screenshot of a window but i don't know how to get a HWND of game.
Here is my code.

   

    #include <d3dx9.h>
    #include <d3dx9tex.h>
    #include <stdio.h>
    
    #pragma comment(lib,"d3d9.lib")
    #pragma comment(lib,"d3dx9.lib")
    
    int main()
    {
        IDirect3DSurface9 *surface;
        IDirect3DDevice9 *g_pd3dDevice;
        IDirect3D9 *g_pD3D;
        D3DDISPLAYMODE d3ddm;
        D3DPRESENT_PARAMETERS d3dpp;
        HWND hWnd = GetConsoleWindow();
    
        if((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
        {
            printf("fail 1");
        }
    
        if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
        {
            printf("fail 2");
        }
    
        ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
    
        d3dpp.Windowed = TRUE;
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
        d3dpp.BackBufferFormat = d3ddm.Format;
        d3dpp.BackBufferHeight = d3ddm.Height;
        d3dpp.BackBufferWidth = d3ddm.Width;
    
        if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,
                                       D3DDEVTYPE_HAL, hWnd,
                                       D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                       &d3dpp, &g_pd3dDevice)))
        {
            printf("fail 3");
        }
        g_pd3dDevice->CreateOffscreenPlainSurface(800, 600, D3DFMT_A8R8G8B8,     D3DPOOL_SCRATCH, &surface, NULL);
        g_pd3dDevice->GetFrontBufferData(0, surface);
        D3DXSaveSurfaceToFile("c:\\tmp\\output.jpg", D3DXIFF_JPG, surface, NULL, NULL);
        surface->Release();
        return 0;
    }


Sponsor:

#2 Endurion   Crossbones+   -  Reputation: 3685

Like
4Likes
Like

Posted 31 July 2013 - 01:44 AM

Wait, what do you want to take the screenshot from? Your own game? Or a different game?

 

If it's your own game you should have a CreateWindow call somewhere, it would be that HWND.

 

If it's a different executable you can't do it simply like that. You have to hook into Direct3d. Here's a sample code, going from there should work easily: http://dxresearch.codeplex.com/


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#3 aramcpp   Members   -  Reputation: 105

Like
0Likes
Like

Posted 31 July 2013 - 02:24 AM

i wont a screenshot of a different game



#4 EddieV223   Members   -  Reputation: 1407

Like
1Likes
Like

Posted 31 July 2013 - 07:20 PM

Do you have to do it in code?  If not just push print screen button on keyboard and paste into any image editor.


If this post or signature was helpful and/or constructive please give rep.

 

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

 

// Easy to learn 2D Game Library c++

SFML2.1 Download http://www.sfml-dev.org/download.php

SFML2.1 Tutorials http://www.sfml-dev.org/tutorials/2.1/

 

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS