Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The Approach Tikhon mentioned is correct. Just to add some code to the answer he gave above</p> <pre><code>import Graphics.Win32.Window import Graphics.Win32.GDI.Bitmap import Graphics.Win32.GDI.HDC import Graphics.Win32.GDI.Graphics2D main = do desktop &lt;- getDesktopWindow -- Grab the Hwnd of the desktop, GetDC 0, GetDC NULL etc all work too hdc &lt;- getWindowDC (Just desktop) -- Get the dc handle of the desktop (x,y,r,b) &lt;- getWindowRect desktop -- Find the size of the desktop so we can know which size the destination bitmap should be -- (left, top, right, bottom) newDC &lt;- 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 &lt;- createCompatibleBitmap hdc width height -- Create a new Bitmap which is compatible with the newly created DC selBmp &lt;- 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. </code></pre> <p>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 :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload