Is it possible to capture the screen (or a window) using Haskell in a Windows environment? (ie, taking a screenshot every few minutes or so). If so, how would one go about doing this (again, in Haskell, for a Windows environment)?
More info: I'm a beginner to Haskell. A friend wants to cut development costs by having me whip together some programs for his accounting firm, but he insists that I use Haskell. He wants a tool that will allow him to monitor the desktops of different Windows XP workstations. It would likely have to be a client/server type application. He only needs to monitor desktop activity, hence why he doesn't want any of the expensive management software that is already on the market. I have sifted through lots of documentation, and only got as far as finding wxHaskell, but I couldn't find much on capturing the screen, especially for Windows environments.
You should be able to do this with the Win32 API. Based on What is the best way to take screenshots of a Window with C++ in Windows?, you need to get the context of the window and then copy the image from it using
GetWindowDC
andBitBlt
respectively.Looking around the Haskell Win32 API documentation, there is a
getWindowDC
function inGraphics.Win32.Window
. This returns anIO HDC
. There is abitblt
function inGraphics.Win32.GDI.Graphics2D
. This function takes anHDC
along with a bunch ofINT
s which presumably correspond to the arguments it takes in C++.Unfortunately, I don't have a Windows machine handy, so I can't write the actual code. You'll have to figure out how to use the Win32 API functions yourself, which might be a bit of a bother.
When you do, it would be great if you factored it into a library and put it up on Hackage--Windows does not usually get much love in Haskell land (as I myself show :P), so I'm sure other Windows programmers would be grateful for an easy way to take screenshots.
You can also do it in a cross-platform way with GTK.
That would not be much different from doing it with C: Taking a screenshot with C/GTK.
The Approach Tikhon mentioned is correct. Just to add some code to the answer he gave above
This was just quickly put together, but it saves a screenshot of to a file named Foo.bmp. Ps. To whomever wrote the Win32 Library, nicely done :)