加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

窗口 – Haskell中的屏幕截图?

发布时间:2020-12-13 20:11:41 所属栏目:Windows 来源:网络整理
导读:是否可以在 Windows环境中使用Haskell捕获屏幕(或窗口)? (即每隔几分钟拍摄一次屏幕截图).如果是这样,那么怎么会这样做(再次,在Haskell,一个Windows环境)? 更多信息: 我是Haskell的初学者.一个朋友希望通过把他的会计师事务所的一些计划汇集在一起??,来削
是否可以在 Windows环境中使用Haskell捕获屏幕(或窗口)? (即每隔几分钟拍摄一次屏幕截图).如果是这样,那么怎么会这样做(再次,在Haskell,一个Windows环境)?

更多信息:
我是Haskell的初学者.一个朋友希望通过把他的会计师事务所的一些计划汇集在一起??,来削减开发成本,但他坚持要使用Haskell.他想要一个工具,允许他监视不同Windows XP工作站的桌面.它可能必须是客户端/服务器类型的应用程序.他只需要监控桌面活动,因此他为什么不想要任何已经在市场上的昂贵的管理软件.我已经筛选了很多文档,只有找到wxHaskell,但是在捕获屏幕方面找不到很多,特别是对于Windows环境.

提到的方法是正确的.只是为了在上面给出的答案中添加一些代码
import 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.

这只是快速放在一起,但它保存了一个名为Foo.bmp的文件的屏幕截图.PS.对于谁写的Win32库,很好做:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读