Calculate inner width+height of PanelGadget items

Share your advanced PureBasic knowledge/code with the community.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Calculate inner width+height of PanelGadget items

Post by Danilo »

Code updated For 5.20+

Code: Select all

;
; Calculate inner width+height of panel items
;
; by Danilo, 29.12.2003
;
Procedure GetPanelItemWidth(PanelGadget)
  ; returns the inner width of panel items
  tc.TC_ITEM\mask = #TCIF_PARAM
  If SendMessage_(GadgetID(PanelGadget),#TCM_GETITEM,0,@tc)
    GetClientRect_(tc\lParam,rect.RECT)
    ProcedureReturn rect\right
  EndIf
EndProcedure

Procedure GetPanelItemHeight(Panelgadget)
  ; returns the inner height of panel items
  tc.TC_ITEM\mask = #TCIF_PARAM
  If SendMessage_(GadgetID(PanelGadget),#TCM_GETITEM,0,@tc)
    GetClientRect_(tc\lParam,rect.RECT)
    ProcedureReturn rect\bottom
  EndIf
EndProcedure

Procedure ScrollbarWidth()
  ; returns the width of windows scrollbars
  ProcedureReturn GetSystemMetrics_(#SM_CXHSCROLL)
EndProcedure

Procedure ScrollbarHeight()
  ; returns the height of windows scrollbars
  ProcedureReturn GetSystemMetrics_(#SM_CYVSCROLL)
EndProcedure


OpenWindow(0,200,200,400,200,"Yo!",#PB_Window_SystemMenu)

PanelGadget(1,5,5,390,190)
AddGadgetItem(1,-1,"Panel Item 1")
ListViewGadget(2,0,0,GetPanelItemWidth(1),GetPanelItemHeight(1))
For a = 1 To 50
  AddGadgetItem(2,-1,"ListView Line "+Str(a))
Next a
AddGadgetItem(1,-1,"Panel Item 2")
ScrollAreaGadget(3,0,0,GetPanelItemWidth(1),GetPanelItemHeight(1),GetPanelItemWidth(1)-ScrollbarWidth(),50*25+10,10,#PB_ScrollArea_BorderLess)
For a = 0 To 49
  ButtonGadget(4+a,20,5+a*25,100,20,"Button "+Str(a+1))
Next a

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
Berikco
Administrator
Administrator
Posts: 1328
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Thanks, just what i needed :)
Berikco
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

Berikco wrote:Thanks, just what i needed :)
Better use this updated procedures:

Code: Select all

  Procedure GetPanelItemWidth(PanelGadget,Item)
    ; by Danilo, 29.12.2003
    ; returns the inner width of panel items
    tc.TC_ITEM\mask = #TCIF_PARAM
    If SendMessage_(GadgetID(PanelGadget),#TCM_GETITEM,Item,@tc)
      GetClientRect_(tc\lParam,rect.RECT)
      ProcedureReturn rect\right
    EndIf
  EndProcedure

  Procedure GetPanelItemHeight(Panelgadget,Item)
    ; by Danilo, 29.12.2003
    ; returns the inner height of panel items
    tc.TC_ITEM\mask = #TCIF_PARAM
    If SendMessage_(GadgetID(PanelGadget),#TCM_GETITEM,Item,@tc)
      GetClientRect_(tc\lParam,rect.RECT)
      ProcedureReturn rect\bottom
    EndIf
  EndProcedure
I´m using this procedures for myself in my current project
and found out later that it doesnt always work after switching
the panel tabs.
With the item/tab specified (beginning with 0), it always works.
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
Berikco
Administrator
Administrator
Posts: 1328
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Danilo wrote:
Berikco wrote:Thanks, just what i needed :)
Better use this updated procedures:

I´m using this procedures for myself in my current project
and found out later that it doesnt always work after switching
the panel tabs.
With the item/tab specified (beginning with 0), it always works.
Ok, replaced the old with this new procedures.
Thanks again ;)
Berikco
Post Reply