Page 1 sur 1

Barre de séparation dans une ComboBoxGadget ?

Publié : mar. 10/mars/2020 11:48
par PhM
Bonjour,

Je cherche le moyen de placer une barre de séparation dans une liste de ComboBoxGadget.
La même chose que fait MenuBar() mais, SANS décaler les numéros de la liste.

Est-ce possible ?

Re: Barre de séparation dans une ComboBoxGadget ?

Publié : mar. 10/mars/2020 13:48
par falsam
C'est une fonctionnalité qui n'existe pas nativement mais des soltutions de contournements existent.

Vu sur le forum anglophone.

Code : Tout sélectionner

;*********************************************
;Sparkies ComboBoxGadget With Menubar type lines v2
;Windows only
;*********************************************
Enumeration
  #WinMain
EndEnumeration

Enumeration
  #ComboMain
EndEnumeration

Procedure WindowCallback(hwnd, msg, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
 
  Select msg
    Case #WM_DRAWITEM
      *DrawItem.DRAWITEMSTRUCT = lParam
      *lpdis.DRAWITEMSTRUCT = lParam
     
      If *DrawItem\CtlType = #ODT_COMBOBOX
        SetBkMode_(*DrawItem\hdc, #TRANSPARENT)
       
        ;***** Set line thickness and left/right margins*****
        lineH = 2
        lMargin = 4
        rMargin = 4
       
        If *DrawItem\itemState & #ODS_FOCUS
          ;****** Color the item when in focus *****
          hiLite = GetSysColor_(#COLOR_HIGHLIGHT)
          brush = CreateSolidBrush_(hiLite)
         
          ;***** If item is highlighted and not selected, we don't color with highlight color behind line *****
          If *DrawItem\itemState  & #ODS_COMBOBOXEDIT = 0
            *DrawItem\rcItem\bottom - (lineH * 2)
            FillRect_(*DrawItem\hdc, *DrawItem\rcItem, brush)
            *DrawItem\rcItem\bottom + (lineH * 2)
          Else
            ;***** If item is highlighted and is selected, we color the entire item rect *****
            FillRect_(*DrawItem\hdc, *DrawItem\rcItem, brush)
            *DrawItem\rcItem\bottom + (lineH * 2)
          EndIf
         
          DeleteObject_(bBrush)
          tColor = GetSysColor_(#COLOR_HIGHLIGHTTEXT)
          SetTextColor_(*DrawItem\hdc, tColor)
        Else
          ;****** Color the item when NOT in focus *****
          FillRect_(*DrawItem\hdc, *DrawItem\rcItem, GetStockObject_(#WHITE_BRUSH))
        EndIf
        If *DrawItem\itemID <> -1
          Text$ = Space(512)
         
          ;***** Get the item text *****
          SendMessage_(*DrawItem\hwndItem, #CB_GETLBTEXT, *DrawItem\itemID, @Text$)
         
          ;****** Draw the text *****
           TextOut_(*DrawItem\hdc, *DrawItem\rcItem\left + 2, *DrawItem\rcItem\top + 2, Text$, Len(Text$))
           
           ;***** If the item data was set to one AND it is not currently selected, draw the line *****
          If *DrawItem\itemData = 1 And *DrawItem\itemState  & #ODS_COMBOBOXEDIT = 0
           
                       
            ;***** Choose line color *****
            lineColor = GetSysColor_(#COLOR_MENU)
            myPen = CreatePen_(#PS_SOLID, lineH, lineColor)
           
            ;***** Select the pen into the hdc *****
            oldPen = SelectObject_(*DrawItem\hdc, myPen)
           
            ;***** Draw the line *****
            MoveToEx_(*DrawItem\hdc, *lpdis\rcItem\left + lMargin, *lpdis\rcItem\bottom - lineH / 2, #Null)
            LineTo_(*DrawItem\hdc, *lpdis\rcItem\right - rMargin, *lpdis\rcItem\bottom - lineH / 2)
           
            ;***** Cleanup *****
            SelectObject_(*DrawItem\hdc, oldPen)
            DeleteObject_(myPen)
           EndIf
           
          EndIf
      EndIf
     
  EndSelect
 
  ProcedureReturn Result
EndProcedure

If OpenWindow(#WinMain, 0, 0, 600, 300, "Combobox Break Line Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_TitleBar )
  ComboBoxGadget(#ComboMain, 10, 10, 300, 25,  #CBS_OWNERDRAWFIXED | #CBS_HASSTRINGS)
  SetWindowCallback(@WindowCallback())
 
  AddGadgetItem(#ComboMain, -1, "Item 0")
  AddGadgetItem(#ComboMain, -1, "Item 1")
  AddGadgetItem(#ComboMain, -1, "Item 2")
  ;***** Items with data set to 1 will have a line added *****
  SetGadgetItemData(#ComboMain, 2, 1)
  AddGadgetItem(#ComboMain, -1, "Item 3")
  AddGadgetItem(#ComboMain, -1, "Item 4")
  AddGadgetItem(#ComboMain, -1, "Item 5")
  ;***** Items with data set to 1 will have a line added *****
  SetGadgetItemData(#ComboMain, 5, 1)
  AddGadgetItem(#ComboMain, -1, "Item 6")
  ;***** Add a little item height *****
  comboH = SendMessage_(GadgetID(#ComboMain), #CB_GETITEMHEIGHT, 0, 0)
  SendMessage_(GadgetID(#ComboMain), #CB_SETITEMHEIGHT, 0, comboH * 1.5)
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

End
:arrow: Source http://forums.purebasic.com/english/vie ... 956e9a4747

Re: Barre de séparation dans une ComboBoxGadget ?

Publié : mar. 10/mars/2020 14:13
par PhM
Merci falsam,
Mais c'est un peu lourd pour mon appli. pour le service rendu.
Peut-être qu'un jour une nouvelle version inclura cela en une ligne...