#Include once "window9.bi"

Function WindowBackgroundImage(ByVal wnd As HWND,ByVal bitmap_ As HBITMAP,ByVal param As Integer=0) 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
    SetClassLong(wnd, GCL_HBRBACKGROUND, Cast(Long,Brush))
    RedrawWindow(wnd, 0, 0, RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN)
  EndIf
  Return cast(integer,Brush)
End Function
