' Custom window background using WMLiberty
' By Brent D. Thorn, 1/2008
' PUBLIC DOMAIN
Open "WMLiberty" For DLL As #wmlib
Open "Background Colors" For Window As #demo
#demo "TrapClose [quit]"
Callback lpfn, OnEraseBkgnd( ULong, ULong, ULong, Long ), Long
Call SetWMHandler HWnd(#demo), _WM_ERASEBKGND, lpfn, 0
[wait]
Scan
CallDLL #kernel32, "Sleep", 50 As Long, ret As Void
GoTo [wait]
[quit]
Close #demo
Close #wmlib
ENd
Function OnEraseBkgnd( hWnd, uMsg, hDC, lParam )
' get the client area's rectangle
Struct rc, _
left As Long, top As Long, _
right As Long, bottom As Long
CallDLL #user32, "GetClientRect", _
hWnd As ULong, rc As Struct, _
ret As Long
' get a white brush
CallDLL #gdi32, "GetStockObject", _
_WHITE_BRUSH As ULong, _
hbrBack As ULong
' fill the client rect with white
CallDLL #user32, "FillRect", _
hDC As ULong, rc As Struct, _
hbrBack As ULong, ret As Long
' suck it in, rectangle!
CallDLL #user32, "InflateRect", _
rc As Struct, -16 As Long, _
-16 As Long, ret As Long
' get a gray brush
CallDLL #gdi32, "GetStockObject", _
_GRAY_BRUSH As ULong, _
hbrBack As ULong
' fill new rect with gray, leaving a white border
CallDLL #user32, "FillRect", _
hDC As ULong, rc As Struct, _
hbrBack As ULong, ret As Long
End Function
Sub SetWMHandler hWnd, uMsg, lpfnCB, lSuccess
CallDLL #wmlib, "SetWMHandler", _
hWnd As ULong, uMsg As ULong, _
lpfnCB As ULong, lSuccess As ULong, _
ret As Long
End Sub |