Item Height in a ComboBoxGadget

Just starting out? Need help? Post your questions and find answers here.
User avatar
blueb
Addict
Addict
Posts: 1044
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Item Height in a ComboBoxGadget

Post by blueb »

Quick question... concerning the list of items inside a ComboBoxGadget().

I can make the ComboBox height any size I need, but I couldn't find a way to alter the default height of the items inside the list. (it's for a touch tablet, and the default is way too small for fingers. haha).

Any pointers?
It's for Windows machine but cross platform would be better.
- It was too lonely at the top.

System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Item Height in a ComboBoxGadget

Post by Shardik »

Code: Select all

EnableExplicit

Define i.I
Define ItemHeight.I

OpenWindow(0, 0, 0, 390, 180, "",
  #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(0, 10, 10, 180, 21)
ComboBoxGadget(1, 200, 10, 180, 21)

For i = 1 To 5
  AddGadgetItem(0, -1,"ComboBox item " + Str(i))
  AddGadgetItem(1, -1,"ComboBox item " + Str(i))
Next

SetGadgetState(0, 0)
SetGadgetState(1, 0)

; ----- Get default item height in 1st ComboBox
ItemHeight = SendMessage_(GadgetID(0), #CB_GETITEMHEIGHT, -1 ,0)
SendMessage_(GadgetID(0), #CB_SETITEMHEIGHT, 0, ItemHeight)

; ----- Add 15 to item height in 2nd ComboBox
SendMessage_(GadgetID(1), #CB_SETITEMHEIGHT, 0, ItemHeight + 15)

; ----- Open 2nd ComboBox to show increased item height
SendMessage_(GadgetID(1), #CB_SHOWDROPDOWN, 1, 0)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: Item Height in a ComboBoxGadget

Post by RASHAD »

For Windows

Code: Select all

Global Text$,Brush,Brush_2

Text$ = Space(#MAX_PATH)

Brush = CreateSolidBrush_($FADC72)
Brush_2 = CreateSolidBrush_($99FEFA)

Procedure WndProc(hWnd, uMsg, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_DRAWITEM
      *DRAWITEM.DRAWITEMSTRUCT = lParam       
      If *DRAWITEM\CtlType = #ODT_COMBOBOX
        SetBkMode_(*DRAWITEM\hDC, #TRANSPARENT)
        If *DRAWITEM\ItemState & #ODS_FOCUS
          FillRect_(*DRAWITEM\hDC,*DRAWITEM\rcItem,Brush)
        Else
          FillRect_(*DRAWITEM\hDC,*DRAWITEM\rcItem,Brush_2)
        EndIf
        SendMessage_(*DRAWITEM\hwndItem,#CB_GETLBTEXT,*DRAWITEM\itemID, @Text$)
        SetTextColor_(*DRAWITEM\hDC, $0)
        *DRAWITEM\rcItem\left = 8
        DrawText_(*DRAWITEM\hDC,@Text$,Len(Text$),*DRAWITEM\rcItem,  #DT_SINGLELINE | #DT_VCENTER )
      EndIf 
  EndSelect 
  ProcedureReturn Result
EndProcedure

LoadFont(0,"Tahoma",12,#PB_Font_Bold)

If OpenWindow(0, 0, 0, 280, 180, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowCallback(@WndProc())
  ComboBoxGadget(0 ,10, 10, 260, 40,#CBS_OWNERDRAWFIXED|#CBS_HASSTRINGS)
  SetGadgetFont(0,FontID(0))
  SendMessage_(GadgetID(0), #CB_SETITEMHEIGHT, 0, 40)
  
  For a = 0 To 10
    AddGadgetItem(0, -1,"ComboBox Item " + Str(a))
  Next
  
  SetGadgetState(0, 2)     
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Egypt my love
User avatar
blueb
Addict
Addict
Posts: 1044
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Item Height in a ComboBoxGadget

Post by blueb »

Thanks Shardik and Rashad.

I thought I'd have to dip into the Windows API... but they work great.

I've added both to my arsenal... funny the topic hasn't come up more often, especially with higher resolution screens (I have a 4k monitor).

Thanks again, very useful stuff.
- It was too lonely at the top.

System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply