Barre de séparation dans une ComboBoxGadget ?

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
PhM
Messages : 151
Inscription : dim. 08/déc./2019 10:50

Barre de séparation dans une ComboBoxGadget ?

Message 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 ?
Avatar de l’utilisateur
falsam
Messages : 7334
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Barre de séparation dans une ComboBoxGadget ?

Message 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
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
PhM
Messages : 151
Inscription : dim. 08/déc./2019 10:50

Re: Barre de séparation dans une ComboBoxGadget ?

Message 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...
Répondre