是否可以在
Windows环境中使用Haskell捕获屏幕(或窗口)? (即每隔几分钟拍摄一次屏幕截图).如果是这样,那么怎么会这样做(再次,在Haskell,一个Windows环境)?
更多信息:
我是Haskell的初学者.一个朋友希望通过把他的会计师事务所的一些计划汇集在一起,来削减开发成本,但他坚持要使用Haskell.他想要一个工具,允许他监视不同Windows XP工作站的桌面.它可能必须是客户端/服务器类型的应用程序.他只需要监控桌面活动,因此他为什么不想要任何已经在市场上的昂贵的管理软件.我已经筛选了很多文档,只有找到wxHaskell,但是在捕获屏幕方面找不到很多,特别是对于Windows环境.
提到的方法是正确的.只是为了在上面给出的答案中添加一些代码
原文链接:https://www.f2er.com/windows/371143.htmlimport Graphics.Win32.Window import Graphics.Win32.GDI.Bitmap import Graphics.Win32.GDI.HDC import Graphics.Win32.GDI.Graphics2D main = do desktop <- getDesktopWindow -- Grab the Hwnd of the desktop,GetDC 0,GetDC NULL etc all work too hdc <- getWindowDC (Just desktop) -- Get the dc handle of the desktop (x,y,r,b) <- getWindowRect desktop -- Find the size of the desktop so we can know which size the destination bitmap should be -- (left,top,right,bottom) newDC <- createCompatibleDC (Just hdc) -- Create a new DC to hold the copied image. It should be compatible with the source DC let width = r - x -- Calculate the width let height = b - y -- Calculate the Height newBmp <- createCompatibleBitmap hdc width height -- Create a new Bitmap which is compatible with the newly created DC selBmp <- selectBitmap newDC newBmp -- Select the Bitmap into the DC,drawing on the DC now draws on the bitmap as well bitBlt newDC 0 0 width height hdc 0 0 sRCCOPY -- use SRCCOPY to copy the desktop DC into the newDC createBMPFile "Foo.bmp" newBmp newDC -- Write out the new Bitmap file to Foo.bmp putStrLn "Bitmap image copied" -- Some debug message deleteBitmap selBmp -- Cleanup the selected bitmap deleteBitmap newBmp -- Cleanup the new bitmap deleteDC newDC -- Cleanup the DC we created.