Habe das ganze etwas verfeinert - evtl. kann es ja jemand (zumindest als Anregung) gebrauchen..
Code: Alles auswählen
DeclareModule Combo
Enumeration ComboBoxGadgetPropertyType
#CBG_Color_DefaultText
#CBG_Color_DefaultBackground
#CBG_Color_DropDownDefaultText
#CBG_Color_DropDownDefaultBackground
#CBG_Color_DropDownSelectedText
#CBG_Color_DropDownSelectedBackground
#CBG_VAlign
#CBG_VAlign_Top
#CBG_VAlign_Center
#CBG_VAlign_Bottom
#CBG_HAlign
#CBG_HAlign_Left
#CBG_HAlign_Center
#CBG_HAlign_Right
EndEnumeration
Declare.l NewCBGadget(Gadget.i, x.l, y.l, Width.l, Height.l, Flags.l = 0)
Declare SetProperty(Gadget.i, Type.a, Property.l)
Declare Callback(result, hWnd, uMsg, wParam, lParam)
EndDeclareModule
Module Combo
EnableExplicit
#CBEM_SETEXTENDEDSTYLE = #WM_USER + 14
#CBES_EX_NOSIZELIMIT = 8
Structure CBG_Property_S
DefaultTextColor.l
DefaultBackgroundColor.l
DropDownDefaultTextColor.l
DropDownDefaultBackgroundColor.l
DropDownSelectedTextColor.l
DropDownSelectedBackgroundColor.l
VAlign.l
HAlign.l
EndStructure
NewMap CBG_Property.CBG_Property_S()
Procedure.l NewCBGadget(Gadget.i, x.l, y.l, Width.l, Height.l, Flags.l = 0)
Shared CBG_Property()
Protected ret.l
ret = ComboBoxGadget(Gadget, x, y, width, 1, Flags | #CBS_OWNERDRAWFIXED | #CBS_HASSTRINGS)
If Gadget = #PB_Any : Gadget = ret : EndIf
SendMessage_(GadgetID(Gadget), #CBEM_SETEXTENDEDSTYLE, 0, #CBES_EX_NOSIZELIMIT)
SendMessage_(GadgetID(Gadget), #CB_SETITEMHEIGHT, -1, Height - 5)
If FindMapElement(CBG_Property(), Str(Gadget)) : DeleteMapElement(CBG_Property()) : EndIf
AddMapElement(CBG_Property(), Str(Gadget))
CBG_Property()\DefaultTextColor = #Black
CBG_Property()\DefaultBackgroundColor = #White
CBG_Property()\DropDownDefaultTextColor = #Black
CBG_Property()\DropDownDefaultBackgroundColor = #White
CBG_Property()\DropDownSelectedTextColor = #White
CBG_Property()\DropDownSelectedBackgroundColor = RGB($1E, $90, $FF)
CBG_Property()\VAlign = #CBG_VAlign_Top
CBG_Property()\HAlign = #CBG_HAlign_Left
ProcedureReturn ret
EndProcedure
Procedure SetProperty(Gadget.i, Type.a, Property.l)
Shared CBG_Property()
If IsGadget(Gadget) And FindMapElement(CBG_Property(), Str(Gadget))
If Type = #CBG_Color_DefaultText : CBG_Property()\DefaultTextColor = Property
ElseIf Type = #CBG_Color_DefaultBackground : CBG_Property()\DefaultBackgroundColor = Property
ElseIf Type = #CBG_Color_DropDownDefaultText : CBG_Property()\DropDownDefaultTextColor = Property
ElseIf Type = #CBG_Color_DropDownDefaultBackground : CBG_Property()\DropDownDefaultBackgroundColor = Property
ElseIf Type = #CBG_Color_DropDownSelectedText : CBG_Property()\DropDownSelectedTextColor = Property
ElseIf Type = #CBG_Color_DropDownSelectedBackground : CBG_Property()\DropDownSelectedBackgroundColor = Property
ElseIf Type = #CBG_VAlign And Property = #CBG_VAlign_Top : CBG_Property()\VAlign = #CBG_VAlign_Top
ElseIf Type = #CBG_VAlign And Property = #CBG_VAlign_Center : CBG_Property()\VAlign = #CBG_VAlign_Center
ElseIf Type = #CBG_VAlign And Property = #CBG_VAlign_Bottom : CBG_Property()\VAlign = #CBG_VAlign_Bottom
ElseIf Type = #CBG_HAlign And Property = #CBG_HAlign_Left : CBG_Property()\HAlign = #CBG_HAlign_Left
ElseIf Type = #CBG_HAlign And Property = #CBG_HAlign_Center : CBG_Property()\HAlign = #CBG_HAlign_Center
ElseIf Type = #CBG_HAlign And Property = #CBG_HAlign_Right : CBG_Property()\HAlign = #CBG_HAlign_Right
EndIf
SetGadgetState(Gadget, GetGadgetState(Gadget))
EndIf
EndProcedure
Procedure Callback(result, hWnd, uMsg, wParam, lParam)
Shared CBG_Property()
Protected brush.i, *DrawItem.DRAWITEMSTRUCT, txt.s, dc.l, s.SIZE, px.l, py.l
If FindMapElement(CBG_Property(), Str(wParam))
If uMsg = #WM_DRAWITEM
*DrawItem = lParam
If *DrawItem\CtlType = #ODT_COMBOBOX
SetBkMode_(*DrawItem\hDC, #TRANSPARENT)
If *DrawItem\ItemState & #ODS_COMBOBOXEDIT
; Current choice
brush = CreateSolidBrush_(CBG_Property()\DefaultBackgroundColor)
FillRect_(*DrawItem\hDC, *DrawItem\rcItem, brush)
DeleteObject_(brush)
SetTextColor_(*DrawItem\hDC, CBG_Property()\DefaultTextColor)
ElseIf *DrawItem\ItemState & #ODS_SELECTED
; Selected choice dropdown
brush = CreateSolidBrush_(CBG_Property()\DropDownSelectedBackgroundColor)
FillRect_(*DrawItem\hDC, *DrawItem\rcItem, brush)
DeleteObject_(brush)
SetTextColor_(*DrawItem\hDC, CBG_Property()\DropDownSelectedTextColor)
Else
; Unselected choice dropdown
brush = CreateSolidBrush_(CBG_Property()\DropDownDefaultBackgroundColor)
FillRect_(*DrawItem\hDC, *DrawItem\rcItem, brush)
DeleteObject_(brush)
SetTextColor_(*DrawItem\hDC, CBG_Property()\DropDownDefaultTextColor)
EndIf
If *DrawItem\itemID <> -1
txt = Space(1024)
SendMessage_(*DrawItem\hwndItem, #CB_GETLBTEXT, *DrawItem\itemID, @txt)
dc=GetDC_(hWnd)
SelectObject_(dc, GadgetID(wParam))
GetTextExtentPoint32_(dc, @txt, Len(txt), s.SIZE)
ReleaseDC_(GadgetID(wParam), dc)
If CBG_Property()\VAlign = #CBG_VAlign_Bottom And *DrawItem\ItemState & #ODS_COMBOBOXEDIT
py = *DrawItem\rcItem\top + (*DrawItem\rcItem\bottom - s\cy) - 3
ElseIf CBG_Property()\VAlign = #CBG_VAlign_Center And *DrawItem\ItemState & #ODS_COMBOBOXEDIT
py = *DrawItem\rcItem\top + (*DrawItem\rcItem\bottom - *DrawItem\rcItem\top - s\cy) / 2
Else
py = *DrawItem\rcItem\top
EndIf
If CBG_Property()\HAlign = #CBG_HAlign_Right And *DrawItem\ItemState & #ODS_COMBOBOXEDIT
px = *DrawItem\rcItem\left + (*DrawItem\rcItem\right - s\cx) - 7
ElseIf CBG_Property()\HAlign = #CBG_HAlign_Center And *DrawItem\ItemState & #ODS_COMBOBOXEDIT
px = *DrawItem\rcItem\left + (*DrawItem\rcItem\right - *DrawItem\rcItem\left - s\cx) / 2
Else
px = *DrawItem\rcItem\left + 4
EndIf
TextOut_(*DrawItem\hDC, px, py, txt, Len(txt))
EndIf
result = #True
EndIf
EndIf
EndIf
ProcedureReturn result
EndProcedure
EndModule
; ******************************************************************************************************
; Quick & Dirty Example :-)
; ******************************************************************************************************
Procedure WindowCallback(hWnd, uMsg, wParam, lParam)
Protected result.l = #PB_ProcessPureBasicEvents
; Callback für ComboBox aufrufen
result = Combo::Callback(result, hWnd, uMsg, wParam, lParam)
If result <> #PB_ProcessPureBasicEvents : ProcedureReturn result : EndIf
ProcedureReturn result
EndProcedure
; --------------------
Define g.l, i.I
OpenWindow(0, 200, 100, 350, 130, "ComboBoxGadget demo")
SetGadgetFont(#PB_Default, LoadFont(0, "Verdana", 10))
ComboBoxGadget(0, 10, 20, 100, 20)
g = Combo::NewCBGadget(#PB_Any, 120, 20, 200, 50)
SetWindowCallback(@WindowCallback())
For i = 1 To 5
AddGadgetItem(0, -1, "Eintrag " + Str(i))
AddGadgetItem(g, -1, "Eintrag " + Str(i))
Next
SetGadgetState(0, 2)
SetGadgetState(g, 2)
combo::SetProperty(g, Combo::#CBG_Color_DropDownSelectedBackground, RGB(220,90,150))
Delay(2000)
combo::SetProperty(g, Combo::#CBG_Color_DefaultText, #Red)
combo::SetProperty(g, Combo::#CBG_VAlign, Combo::#CBG_VAlign_Center)
combo::SetProperty(g, Combo::#CBG_HAlign, Combo::#CBG_HAlign_Center)
Delay(2000)
combo::SetProperty(g, Combo::#CBG_Color_DefaultText, #Yellow)
combo::SetProperty(g, Combo::#CBG_Color_DefaultBackground, #Black)
combo::SetProperty(g, Combo::#CBG_VAlign, Combo::#CBG_VAlign_Bottom)
combo::SetProperty(g, Combo::#CBG_HAlign, Combo::#CBG_HAlign_Right)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow