Because the ComboBoxGadet doesn't innately support coloring, I made a patch.
Best regards
Wolf
Code: Select all
; By Hroudtwolf (PureBasic-Lounge.com)
; 04/25/2009
; PureBasic 4.x
; Windows
Structure tCBGEX
hBackgroundBrush .i
nFrontColor .i
*oProc
EndStructure
Procedure _CBGExCB ( hWnd.i , idMsg.i , wParam.i , lParam.i )
Protected *CBGEx.tCBGEX = GetProp_( hWnd , "CBGEXDATA" )
Select idMsg
Case #WM_CTLCOLOREDIT , #WM_CTLCOLORLISTBOX
SetBkMode_( wParam , #TRANSPARENT )
SetTextColor_( wParam , *CBGEx\nFrontColor )
ProcedureReturn *CBGEx\hBackgroundBrush
Case #WM_DESTROY
DeleteObject_( *CBGEx\hBackgroundBrush )
SetWindowLongPtr_( hWnd , #GWL_WNDPROC , *CBGEx\oProc )
FreeMemory ( *CBGEx )
EndSelect
ProcedureReturn CallWindowProc_( *CBGEx\oProc , hWnd.i , idMsg.i , wParam.i , lParam.i )
EndProcedure
Procedure.i ComboBoxGadgetEx ( idGadget.i , nX.i , nY.i , nWidth.i , nHeight.i , btFlags.i = #Null )
Protected nResult .i
Protected hWnd .i
Protected *CBGEx .tCBGEX
nResult = ComboBoxGadget ( idGadget , nX , nY , nWidth , nHeight , btFlags )
If Not nResult
ProcedureReturn #Null
EndIf
If idGadget = #PB_Any
hWnd = GadgetID ( nResult )
Else
hWnd = GadgetID ( idGadget )
EndIf
*CBGEx = AllocateMemory ( SizeOf ( tCBGEX ) )
*CBGEx\oProc = GetWindowLongPtr_( hWnd , #GWL_WNDPROC )
*CBGEx\nFrontColor = GetSysColor_( #COLOR_BTNTEXT )
*CBGEx\hBackgroundBrush = CreateSolidBrush_( GetSysColor_( #COLOR_WINDOW ) )
SetProp_( hWnd , "CBGEXDATA" , *CBGEx )
SetWindowLongPtr_( hWnd , #GWL_WNDPROC , @ _CBGExCB () )
InvalidateRect_( hWnd , #Null , #True )
ProcedureReturn nResult
EndProcedure
Procedure.i ComboBoxGadgetEx_Color ( idGadget.i , nMode.i , nColor.i )
Protected *CBGEx.tCBGEX
If IsGadget ( idGadget )
*CBGEx = GetProp_( GadgetID ( idGadget ) , "CBGEXDATA" )
If Not *CBGEx
ProcedureReturn #False
EndIf
Select nMode
Case #PB_Gadget_BackColor
DeleteObject_( *CBGEx\hBackgroundBrush )
*CBGEx\hBackgroundBrush = CreateSolidBrush_( nColor )
Case #PB_Gadget_FrontColor
*CBGEx\nFrontColor = nColor
Default
ProcedureReturn #False
EndSelect
InvalidateRect_( hWnd , #Null , #True )
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
;--- Test code
Define.i idGadget
OpenWindow ( #PB_Any , #PB_Ignore , #PB_Ignore , 200 , 150 , "ComboBoxGadgetEx" , #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
idGadget = ComboBoxGadgetEx ( #PB_Any , 5 , 5, 190 , 20 )
AddGadgetItem ( idGadget , -1, "Pink Floyd: The Wall" )
AddGadgetItem ( idGadget , -1, "Pink Floyd: The Final Cut" )
AddGadgetItem ( idGadget , -1, "Black Sabbath: Paranoid" )
AddGadgetItem ( idGadget , -1, "Nazareth: Loud’n’proud" )
AddGadgetItem ( idGadget , -1, "Nazareth: Expect No Mercy" )
AddGadgetItem ( idGadget , -1, "The Rolling Stones: Tattoo You" )
SetGadgetState ( idGadget , 0 )
ComboBoxGadgetEx_Color ( idGadget , #PB_Gadget_BackColor , $0103A7 )
ComboBoxGadgetEx_Color ( idGadget , #PB_Gadget_FrontColor , $24FF84 )
Repeat
If WaitWindowEvent() = #PB_Event_CloseWindow
End
EndIf
ForEver