' Custom 2-Color ListBox Demo
' By Brent D. Thorn, 2003, 2006
' PUBLIC DOMAIN
NoMainWin
Global g.hbrListBack, g.crListBack, g.crListFore
g.crListBack = RGB(191, 32, 32) ' Med. Red
g.crListFore = RGB(0, 255, 0) ' Br. Green
CallDLL #gdi32, "CreateSolidBrush", _
g.crListBack As ULong, _
g.hbrListBack As ULong
Open "WMliberty.dll" For DLL As #wmlib
demo.lstMX$(1) = "Merry"
demo.lstMX$(2) = "Christmas"
ListBox #demo.lstMX, demo.lstMX$(), DoNothing, 10, 10, 100, 100
Open "Colored Listbox" For Dialog As #demo
#demo "TrapClose demo.Close"
#demo.lstMX "Font Impact 12"
'Create subclass of parent window.
'Trap the WM_CTLCOLORLISTBOX message.
Callback lpfn, OnCtlColorListbox( ULong, ULong, ULong, ULong), Long
Call SetWMHandler HWnd(#demo), _WM_CTLCOLORLISTBOX, lpfn, g.hbrListBack
Call DoEvents
Sub DoEvents
[localLoop]
Scan
CallDLL #kernel32, "Sleep", 50 As ULong, ret As Void
GoTo [localLoop]
End Sub
Sub demo.Close me$
CallDLL #gdi32, "DeleteObject", _
g.hbrListBack As ULong, ret As Long
Close #me$
' Must close window before closing WMLiberty.
Close #wmlib
End
End Sub
Function OnCtlColorListbox( hWnd, uMsg, hDC, hwndList )
If hwndList = HWnd(#demo.lstMX) Then
Call SetTextColor hDC, g.crListFore
Call SetBkColor hDC, g.crListBack
'Return the bg brush.
OnCtlColorListbox = g.hbrListBack
End If
End Function
Function RGB( R, G, B )
RGB = R + 256 * G + 65536 * B
End Function
Sub SetBkColor hDC, crBack
CallDLL #gdi32, "SetBkColor", _
hDC As ULong, crBack As ULong, _
ret As ULong
End Sub
Sub SetTextColor hDC, crText
CallDLL #gdi32, "SetTextColor", _
hDC As ULong, crText As ULong, _
ret As ULong
End Sub
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
Sub DoNothing h$
End Sub |