#include once "window9.bi"

Function WindowBackgroundImage(ByVal wnd As HWND, ByVal bitmap_ As HBITMAP, ByVal param As Integer) As integer Export
	If param=1 Then
		Dim rr As RECT
		GetClientRect(wnd,@rr)
		bitmap_=Resize_image(bitmap_,rr.right-rr.left,rr.bottom-rr.top)
	EndIf
	Var Brush = CreatePatternBrush(bitmap_)
	If Brush Then
		SetClassLongPtr(wnd, GCLP_HBRBACKGROUND, Cast(Long_ptr,Brush))
		RedrawWindow(wnd, 0, 0, RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN)
	EndIf
	Return cast(integer,Brush)
End Function
