Here is a quick and dirty example of using the "System.Drawing" assembly to create a clipped bitmap of a screenshot.
;; Load needed assembly.
ObjectClrOption('useany', 'System.Drawing')
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Example from the help file
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Takes a bitmap snapshot of the screen and pastes it to the clipboard.
Snapshot(0)
;returns the size of buffer needed for a subsequent BinaryAlloc,
;but doesn't attempt to place the contents of clipboard into a buffer
size=BinaryClipGet(0,8)
;allocates a data buffer
bb=BinaryAlloc(size)
;read file format type CF_DIB
BinaryClipGet(bb,8)
; need to add first 14 bytes to make it
; a BMP file format
bmpdatasize=14
bb2=BinaryAlloc(size + bmpdatasize)
;The characters identifying the bitmap.'BM'
BinaryPokeStr(bb2, 0, "BM")
;Complete file size in bytes.
BinaryPoke4(bb2,2,size + bmpdatasize)
;Reserved
BinaryPoke4(bb2,6,0)
;Data offset
headersize=BinaryPeek4(bb,0)
dataoffset = headersize + bmpdatasize
BinaryPoke4(bb2,10,dataoffset)
BinaryCopy(bb2,bmpdatasize,bb,0,size)
; Note:Moved bitmap file name to a variable.
BmpFile = "c:\temp\screenshot.bmp"
BinaryWrite(bb2,BmpFile)
BinaryFree(bb)
BinaryFree(bb2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Use the System.Drawing.Bitmap class to create
;; a new image of just part of the screen.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
objBmp = ObjectClrNew('System.Drawing.Bitmap', BmpFile)
bmpH = objBmp.Height()
bmpW = objBmp.Width()
; Take a slice out of the middle
nX = bmpW/4
nY = BmpH/4
nW = nX * 2
nH = nY * 2
objRect = ObjectClrNew('System.Drawing.Rectangle', nX, nY, nW, nH)
nDontCare = 0
nDontCare = ObjectClrType('System.Drawing.Imaging.PixelFormat', nDontCare )
objCrop = objBmp.Clone(objRect, nDontCare)
Clip = 'C:\temp\Clipped.bmp'
objCrop.Save(Clip)
; Clean up.
objCrop.Dispose()
objBmp.Dispose()
Run('mspaint.exe', Clip)
Interesting enough you can use dotNet to get the screen shot but the WIL ScreenShot function does the job without the additional learning curve.
Here's a rough approximation of a "pure" dotNet approach:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Pure FCL approach.
;; Load needed assembly.
ObjectClrOption('useany', 'System.Drawing')
Clip = 'C:\temp\Clipped.bmp'
; Take a slice from somewhere on the screen.
nX = WinMetrics(0)/4
nY = WinMetrics(1)/4
nW = nX * 2
nH = nY * 2
Format32bppArgb = ObjectClrType('System.Drawing.Imaging.PixelFormat', 2498570)
objBmp = ObjectClrNew('System.Drawing.Bitmap', nX, nY, Format32bppArgb )
objGraphics = ObjectClrNew('System.Drawing.Graphics')
memGraphic = objGraphics.FromImage(objBmp)
; Copy a portion of the screen to a bitmap and save it to a file.
Size = ObjectClrNew('System.Drawing.Size', nW, nH)
memGraphic.CopyFromScreen(nX, nY, 0, 0, Size)
Clip = 'C:\temp\Clipped.bmp'
objBmp.Save(Clip)
; View the result.
Run('mspaint.exe', Clip)
It could be taken a step farther by having the clipped image drawn in a dotNet form window.