Code: Select all
;Autor: netmaestro
EnableExplicit
Define EventID
Define hIcon1
Define hIcon2
Define hIcon3
Global CBID = 1
Global CBIconSize = 32;oder 64
Global CBTextTopPos = 10;oder 28
hIcon1 = ExtractIcon_(0, #PB_Compiler_Home + "PureBasic.exe", 1)
hIcon2 = ExtractIcon_(0, "shell32.dll", 10)
hIcon3 = ExtractIcon_(0, "shell32.dll", 20)
Global Dim CBIcons(2)
CBIcons(0) = hIcon1
CBIcons(1) = hIcon2
CBIcons(2) = hIcon3
Procedure FreehIcons()
Protected k
For k = 0 To ArraySize(CBIcons())
DestroyIcon_(CBIcons(k))
Next
EndProcedure
Procedure WinProc(hwnd, msg, wparam, lparam)
Protected result
Protected *dis.DRAWITEMSTRUCT
Protected text$
Protected hBrush
Protected oldbrush
Protected *mis.MEASUREITEMSTRUCT
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_DRAWITEM
*dis.DRAWITEMSTRUCT = lparam
If *dis\ctlid = CBID
With *dis
text$ = GetGadgetItemText(\ctlid, \itemid)
If \itemstate & #ODS_SELECTED
hBrush = CreateSolidBrush_(GetSysColor_(#COLOR_HIGHLIGHT))
oldbrush = SelectObject_(\hdc, hBrush)
FillRect_(\hdc, \rcitem, hBrush)
DeleteObject_(hBrush)
DrawFocusRect_(\hdc, \rcitem)
If \itemid >=0 And \itemid <= CountGadgetItems(\ctlid)-1
DrawIconEx_(\hdc, 4,\rcitem\top+1, CBIcons(\itemid),CBIconSize,CBIconSize, 0,0,#DI_NORMAL|#DI_COMPAT)
EndIf
SelectObject_(\hdc, oldbrush)
SetBkColor_( \hdc, GetSysColor_(#COLOR_HIGHLIGHT))
TextOut_( \hdc, \rcItem\left+CBIconSize+8, \rcItem\top+CBTextTopPos, text$, Len(text$))
Else
hBrush = CreateSolidBrush_(#White)
oldbrush = SelectObject_(\hdc, hBrush)
FillRect_(\hdc, \rcitem, hBrush)
DeleteObject_(hBrush)
SelectObject_(\hdc, oldbrush)
If \itemid >=0 And \itemid <= CountGadgetItems(\ctlid)-1
DrawIconEx_(\hdc, 4,\rcitem\top+1, CBIcons(\itemid),CBIconSize,CBIconSize, 0,0,#DI_NORMAL)
EndIf
SetBkColor_( \hdc, #White)
TextOut_( \hdc, \rcItem\left+CBIconSize+8, \rcItem\top+CBTextTopPos, text$, Len(text$))
EndIf
EndWith
EndIf
Case #WM_MEASUREITEM
*mis.MEASUREITEMSTRUCT = lparam
If *mis\ctlid = CBID
*mis\itemheight = CBIconSize+2
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowCallback(@WinProc())
ComboBoxGadget(1, 10, 10, 200, CBIconSize+8, #CBS_OWNERDRAWVARIABLE | #CBS_HASSTRINGS)
AddGadgetItem(1, -1, "Eintrag 1", 0, 0)
AddGadgetItem(1, -1, "Eintrag 2", 0, 0)
AddGadgetItem(1, -1, "Eintrag 3", 0, 0)
SetGadgetState(1, 0)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
FreehIcons()
End
EndIf
ForEver
EndIf
1) How to have multiple custom combos on the same window? A callback for each? (owch).
2) The drop down drops by only one row - so a lot of clicking is required to select an item.
3) Tiny text - having added a large icon, a bigger font height for the text would be good.