#include once "window9.bi"

Using GDIPLUS

Dim shared ULONG_PTR_01 AS ULONG_PTR
DIM GDIPLUSSTARTUPINPUT_01 AS GDIPLUSSTARTUPINPUT
GDIPLUSSTARTUPINPUT_01.GdiplusVersion = 1
IF (GDIPLUSSTARTUP(@ULONG_PTR_01, @GDIPLUSSTARTUPINPUT_01, NULL) <> 0) THEN
	PRINT "FAIL"
End If

Function Grab_Image(ByVal imagesourse As HBITMAP,ByVal x As Integer,ByVal y As Integer, ByVal w As Integer, ByVal h As Integer) As HBITMAP Export
	Dim As GPIMAGE Ptr pImage1
	Dim As GPIMAGE Ptr pImage2
	Dim As HBITMAP      Image
	GdipCreateBitmapFromHBITMAP(imagesourse, NULL, Cast(GpBitmap ptr Ptr,@pImage1))
	GdipCloneBitmapArea (x,y,w,h, 0, Cast(GpBitmap ptr ,pImage1) , Cast(GpBitmap ptr Ptr,@pImage2))
	GdipCreateHBITMAPFromBitmap(Cast(GpBitmap ptr ,pImage2) ,@Image,0)
	GdipDisposeImage pImage1
	GdipDisposeImage pImage2
	Return Image
End Function
