To capture a screen with Gdiplus-X is a very easy task too.
Basically, all we need to do is to call the FromScreen() method from the Bitmap class. To ease this task, this method brings some different overloads.
IMPORTANT:
All samples below use the new GDIPlus-X library, that is still in ALPHA version, but is already stable and reliable to do the majority of GDI+ tasks. Download the latest stable release from Codeplex:
http://www.codeplex.com/Wiki/View.aspx?ProjectName=VFPX&title=GDIPlusX
1 - Capture a Form Screen sending the hWnd of the form or the form as an object
DO LOCFILE("System.App")
LOCAL loCaptureBmp AS xfcBitmap
WITH _Screen.System.Drawing
loCaptureBmp = .Bitmap.FromScreen(Thisform.HWnd)
* Could be also:
* loCaptureBmp = _screen.system.Drawing.Bitmap.FromScreen(Thisform)
loCaptureBmp.Save("c:\Captured.png", .Imaging.ImageFormat.Png)
ENDWITH
2 - Capture the whole screen
In this case, no parameter is needed to be passed
DO LOCFILE("System.App")
LOCAL loCaptureBmp AS xfcBitmap
WITH _Screen.System.Drawing
loCaptureBmp = .Bitmap.FromScreen()
loCaptureBmp.Save("c:\CapturedScreen.png", .Imaging.ImageFormat.Png)
ENDWITH
3 - Capture the screen of a form cutting off its borders and title.
For this task we use the SYSMETRIC() function to obtain the measure of the screen elements, such as the title height, top and left borders. Then we use another overload, sending the hWnd, and the coordinates of the form to be captured.
DO LOCFILE("System.App")
LOCAL lnTitleHeight, lnLeftBorder, lnTopBorder
lnTitleHeight = SYSMETRIC(9)
lnLeftBorder = SYSMETRIC(3)
lnTopBorder = SYSMETRIC(4)
LOCAL loCaptureBmp AS xfcBitmap
WITH _Screen.System.Drawing
loCaptureBmp = .Bitmap.FromScreen(;
Thisform.HWnd, ;
lnLeftBorder, ;
lnTitleHeight + lnTopBorder, ;
Thisform.Width, ;
Thisform.Height)
loCaptureBmp.Save("c:\Captured.png", .Imaging.ImageFormat.Png)
ENDWITH
4 - Capture all forms in the screen.
This is very simple too. Just create a loop through all _screen forms and capture each of them, sending the form.hWnd as a parameter.
DO LOCFILE("System.App")
LOCAL loCaptureBmp AS xfcBitmap
LOCAL n
LOCAL loForm AS Form
n = 1
WITH _Screen.System.Drawing
FOR EACH loForm IN _Screen.Forms
loCaptureBmp = .Bitmap.FromScreen(loForm.HWnd)
loCaptureBmp.Save("c:\CapturedForm" + TRANSFORM(n) + ".png", ;
.Imaging.ImageFormat.Png)
n = n + 1
ENDFOR
ENDWITH