SFML community forums

Help => Graphics => Topic started by: canawa on February 03, 2010, 06:05:41 am

Title: Saving the contents of the foreground window to a file
Post by: canawa on February 03, 2010, 06:05:41 am
Hi, I'm just making a little program that needs to do what it says in the topic title for some reason. When I say foreground window, I mean whatever was open before the program was run. Is this possible in SFML?

The code below creates a new window with the dimensions of the foreground window, but doesn't copy its contents (doesn't make the copy window appear, either), so the .png file that is created is full of random garbage instead of a copy of the window contents.

Code: [Select]
{
HWND hWindow = GetForegroundWindow(); //From <windows.h>

if(hWindow == NULL)
throw "Foreground window error";

RenderWindow window(hWindow, WindowSettings(24, 8, 0));
Image image = window.Capture();
image.SaveToFile("test.png");
}


Is there a way to make this work, or do I have to use OpenGL, Win32, or something like that to accomplish this?
Title: Saving the contents of the foreground window to a file
Post by: Laurent on February 03, 2010, 08:12:40 am
You won't be able to do this with SFML, because it creates its own pixel storage which has nothing to do with the previous contents of the window.

It shouldn't be hard to achieve with Win32 functions.
Title: Saving the contents of the foreground window to a file
Post by: canawa on February 03, 2010, 09:11:33 pm
Oh well, no shortcuts for me.

Thanks for the reply, it's rare to see a library author who answers questions personally. Off to Win32 I go!