ListViewGadget() with Dynamic Horizontal ScrollBar [Windows]

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

ListViewGadget() with Dynamic Horizontal ScrollBar [Windows]

Post by RASHAD »

Hi
The title say it all

Code: Select all

   LoadFont(0,"Tahoma",12)
  If OpenWindow(0, 0, 0, 270, 200, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ListViewGadget(0, 10, 10, 250, 120,#WS_HSCROLL)
    For a = 1 To 12
      AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview")
    Next
    
    ButtonGadget(1,10,150,80,25,"Add item(s)")
    ButtonGadget(2,100,150,80,25,"Remove item")
    
    hdc = GetDC_(GadgetID(0))
    SetGadgetFont(0,FontID(0))
    fontid = GetGadgetFont(0)
    SelectObject_(hdc, fontid)
    size.SIZE
    sitem = -1
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          sitem = GetGadgetState(0)          
        
        Case 1          
          AddGadgetItem (0, -1, "Listview Listview  Listview  Listview  Listview Listview Listview")
          AddGadgetItem (0, -1, "Listview Listview  Listview  Listview  Listview Listview Listview Listview Listview")
          items = CountGadgetItems(0)
          SendMessage_(GadgetID(0),#LB_GETHORIZONTALEXTENT,0,0)
          For item = 0 To items
            text$ = GetGadgetItemText(0,item)           
            GetTextExtentPoint32_(hdc,@text$,Len(text$),size)
            If size\cx > oldcx
               oldcx = size\cx
            EndIf
          Next
          SendMessage_(GadgetID(0),#LB_SETHORIZONTALEXTENT,oldcx+10,0)
          oldcx = 0
          
        Case 2
          If sitem >= 0          
            RemoveGadgetItem (0,sitem)
            items = CountGadgetItems(0)
            SendMessage_(GadgetID(0),#LB_GETHORIZONTALEXTENT,0,0)
            For item = 0 To items
              text$ = GetGadgetItemText(0,item)           
              GetTextExtentPoint32_(hdc,@text$,Len(text$),size)
              If size\cx > oldcx
                 oldcx = size\cx
              EndIf
            Next
            SendMessage_(GadgetID(0),#LB_SETHORIZONTALEXTENT,oldcx+10,0)
            oldcx = 0 : sitem = -1
          Else
            MessageRequester("Info","No item selected ",#MB_OK|#MB_ICONINFORMATION)
          EndIf

      EndSelect              
  EndSelect
Until Quit = 1
EndIf
Edit : Update
Last edited by RASHAD on Wed Feb 27, 2019 1:40 pm, edited 1 time in total.
Egypt my love
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: ListViewGadget() with Dynamic Horizontal ScrollBar [Wind

Post by Michael Vogel »

Well done :shock:

I was nervous for a second as the initial content does not get checked, but your code is great - I'd add a SetGadgetFont(0,FontID(0)) anyhow :wink:
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: ListViewGadget() with Dynamic Horizontal ScrollBar [Wind

Post by RASHAD »

Previous post updated
Egypt my love
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ListViewGadget() with Dynamic Horizontal ScrollBar [Wind

Post by Kwai chang caine »

Works great here
Thanks a lot for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply