#include ONCE "window9.bi"

function  CreateCopyImageWindow (hWin as any ptr , iFlag as Long = 0) as Hbitmap export
	
	dim as Long iX , iY , iWidth , iHeight , iDepth
	
	dim as GDKWindow ptr desk = gdk_get_default_root_window()
	
	dim as GdkRectangle rc
	
	#ifdef __USE_GTK3__
	
	gdk_window_get_geometry(desk, @iX, @iY, @iWidth, @iHeight)
	
	#else
	
	gdk_window_get_geometry(desk, @iX, @iY, @iWidth, @iHeight , @iDepth)
	
	#endif	
	
	if hWin andalso iFlag =  1 then
		
		gdk_window_get_frame_extents (hWin, @rc)
		
	elseif	hWin andalso iFlag =  0 then
		
		gdk_window_get_frame_extents (gtk_widget_get_window(hWin), @rc)
		
	EndIf
	
	if iWidth <> 0 andalso iHeight <> 0 then
		
		#ifdef __USE_GTK3__
		
		return gdk_pixbuf_get_from_window (desk, rc.x, rc.y, rc.Width, rc.Height)
		
		#else
		
		return  gdk_pixbuf_get_from_drawable(NULL , desk, gdk_colormap_get_system(),  rc.x, rc.y, 0, 0, rc.Width, rc.Height)
		
		#endif
		
	endif

End Function