#include once "window9.bi"

function CreateCopyImageRect(ByVal window_ As HWND,ByVal x As long,ByVal y As long,ByVal width_ As long,ByVal height_ As long, ByVal iFlag as Long = 0) As HBITMAP Export
	Dim as integer w,h
	Dim as HWND DSKWND = window_
	w = width_ 
	h = height_ 
	Dim as HDC display_dc      = GetDC( DSKWND )
	dim as HDC bitmap_dc       = CreateCompatibleDC( display_dc )
	dim as HBITMAP bitmap      = CreateCompatibleBitmap( display_dc, w, h )
	dim as HGDIOBJ null_bitmap = SelectObject( bitmap_dc, bitmap )
	BitBlt( bitmap_dc, 0, 0, w, h, display_dc, x, y, srcCOPY )
	Function=CopyImage(bitmap,IMAGE_BITMAP,0,0,LR_COPYRETURNORG)
	DeleteDC(display_dc)
	DeleteDC(bitmap_dc)
	DeleteObject(Bitmap)
End Function
