Jump to content
  • Advertisement
Sign in to follow this  

Draw Screenshot of another window in DX app

This topic is 2868 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 would like to show the contents of another window as an overlay of some sort on the screen of a DX9 application (VBS2, which is essentially ArmA). I haven't created either of these apps, so the less obtrusive the better. The DX app I'm working with has a plugin system, that gives me access to the Direct9 Device, and I can use that to draw some basic things like text, and lines to draw some shapes, and also load an image.

What I really want to do is take the image of another window (one that will be changing, so let's say windows Media Player for now) and display that as a sprite (or texture, what have you).

I've been searching through the forums, and I've found some similar posts, and I have been able to follow the windows GDI stuff to save a bmp from a window as well, but I'm having some trouble tying the two parts together to get the window bmp in memory and reuse to draw onto the screen, rather than saving to a file first, every frame.

I followed the code from this post on how to save a screenshot, and instead of using the screen, I've tweaked it to use FindWindow so I can get a running app, instead of the whole screen. Luckily when saving a bmp to disk it also works just fine even when the DX app is open over this windows app. Lucky start...

I have been reading some other posts here on using the data in memory to create a texture, but this is where I'm getting stuck.

Right now, to load an image from the disk, I'm first taking the screenshot (as in the link above), and then doing:

// first I create a global for the texture and create a DX sprite
IDirect3DTexture9 *imgTex;
ID3DXSprite *imgSprite = NULL;

// in my init stuff:
D3DXCreateSprite(d3device, &imgSprite);

// then when I want to get an image to show, I use the method described in the link above to create a bmp and then do this to load it as a texture
D3DXCreateTextureFromFileEx(d3device, "C:/image.bmp", 243, 88, D3DX_DEFAULT, NULL, D3DFMT_R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3D_DEFAULT, D3DCOLOR_XRGB(200, 0, 200), NULL, NULL, &imgTex);

Then, in my main loop, I draw that texture:


D3DXVECTOR3 spritecentre(0, 0, 0);
D3DXVECTOR3 spritepos(600, 600, 0);

imgSprite->Draw(imgTex, NULL, &spritecentre, &spritepos, D3DCOLOR_ARGB(100, 255, 255, 255));


Now this seems to work our pretty well. I set the color alpha in the imgSprite->Draw call because I wanted to make it semi-transparent. Not really important to the issue at hand, but just in case anyone was wondering why.

So - as I said, what I would like to do is get that image from the window, and instead of saving it just once to disk and loading it, I want to recapture that window's screenshot every frame (or close to) and update the texture. I know there's the method for CreateTexture and it can be set to dynamic, which I'm trying to use, but no matter what data I try to copy into it's pointer, nothing shows up...

It feels like I'm close, but I'm definitely missing something...

Any help will be greatly appreciated!!

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!