Tikhon提到的方法是正確的。只是添加一些代碼到他上面
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的圖書館,很好地完成:)
你是否認爲只是從Haskell調用外部程序,它需要一個截圖? – Probie 2012-08-15 03:01:25
@Probie事實上,我已經考慮過在Haskell中製作客戶端和服務器,並以不同的時間間隔發送屏幕截圖。但是,這看起來非常直觀。爲什麼即使使用Haskell開始,如果只有這樣一小部分軟件實際上是Haskell。 唉,這是Haskell社區應該解決的問題。如果我們希望Haskell更加突出,我們肯定需要解決這些類型的問題。 – 2012-08-15 03:09:16