Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Saving the contents of the foreground window to a file  (Read 1684 times)

0 Members and 1 Guest are viewing this topic.

canawa

  • Newbie
  • *
  • Posts: 2
    • View Profile
Saving the contents of the foreground window to a file
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Saving the contents of the foreground window to a file
« Reply #1 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.
Laurent Gomila - SFML developer

canawa

  • Newbie
  • *
  • Posts: 2
    • View Profile
Saving the contents of the foreground window to a file
« Reply #2 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!

 

anything