Panel Top and Bottom Border Size

Windows specific forum
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Panel Top and Bottom Border Size

Post by ChrisR »

How to get the Top and Bottom border size of a panel
The 2 borders are 5 pixels long: 0+5, 1+4, 2+3, 3+2 ?
I don't have that concern for other containers

Code: Select all

Define i.i, rcWind.Rect, rcClient.RECT

OpenWindow(0, 0, 0, 440, 240, "", #PB_Window_SystemMenu)
ScrollAreaGadget(1, 20, 20, 400, 200, 500, 300, 10)
CloseGadgetList()
ScrollAreaGadget(2, 20, 20, 400, 200, 300, 100, 10, #PB_ScrollArea_Flat)
CloseGadgetList()
CanvasGadget(3, 20, 20, 400, 200, #PB_Canvas_Container|#PB_Canvas_Border)
CloseGadgetList()
ContainerGadget(4, 20, 20, 400, 200, #PB_Container_Raised)
CloseGadgetList()
PanelGadget(5, 20, 20, 400, 200)
AddGadgetItem(5, -1, "Tab 1")
CloseGadgetList()

For i = 1 To 5
  If IsGadget(i)
  Select GadgetType(i)
    Case #PB_GadgetType_Canvas, #PB_GadgetType_Container
      GetClientRect_(GadgetID(i), @rcClient)
      GetWindowRect_(GadgetID(i), @rcWind)
      Debug "Gadget Border(" + i + ") " + Str((rcWind\right - rcWind\left) - rcClient\right) + "x" + Str((rcWind\bottom - rcWind\top) - rcClient\bottom)
      
    Case #PB_GadgetType_ScrollArea
      GetClientRect_(GadgetID(i), @rcClient)
      GetWindowRect_(GadgetID(i), @rcWind)
      If (GetWindowLongPtr_(GadgetID(i), #GWL_STYLE) & #WS_VSCROLL)
        Debug "Scroll size(" + i + ") " + Str(GetSystemMetrics_(#SM_CXVSCROLL)) + "x" + Str(GetSystemMetrics_(#SM_CYHSCROLL))
        Debug "Gadget Border(" + i + ") " + Str((rcWind\right - rcWind\left) - rcClient\right - GetSystemMetrics_(#SM_CXVSCROLL)) + "x" + Str((rcWind\bottom - rcWind\top) - rcClient\bottom - GetSystemMetrics_(#SM_CYHSCROLL))
      Else
        Debug "Gadget Border(" + i + ") " + Str((rcWind\right - rcWind\left) - rcClient\right) + "x" + Str((rcWind\bottom - rcWind\top) - rcClient\bottom)
      EndIf
      
    Case #PB_GadgetType_Panel
      Debug "TabHeight(" + i + ") " + Str(GetGadgetAttribute(i, #PB_Panel_TabHeight))
      ;GetClientRect_(GadgetID(i), @rcClient)
      ;GetWindowRect_(GadgetID(i), @rcWind)
      ;Debug "Window Border(" + i + ") " + Str((rcWind\right - rcWind\left) - rcClient\right) + "x" + Str((rcWind\bottom - rcWind\top) - rcClient\bottom)
      Debug "Gadget Border(" + i + ") " + Str(GadgetWidth(i) - GetGadgetAttribute(i, #PB_Panel_ItemWidth)) + "x" + Str(GadgetHeight(i) - GetGadgetAttribute(i, #PB_Panel_TabHeight) - GetGadgetAttribute(i, #PB_Panel_ItemHeight))
      Debug "Left/Right Border(" + i + ") " + Str((GadgetWidth(i) - GetGadgetAttribute(i, #PB_Panel_ItemWidth))/2)
      Define TopBorder = Int((GadgetHeight(i) - GetGadgetAttribute(i, #PB_Panel_TabHeight) - GetGadgetAttribute(i, #PB_Panel_ItemHeight))/2)
      Debug "Top Border(" + i + ") !!!!! " + Str(TopBorder)
      Debug "Bottom Border(" + i + ") !!!!! " + Str(GadgetHeight(i) - GetGadgetAttribute(i, #PB_Panel_TabHeight) - GetGadgetAttribute(i, #PB_Panel_ItemHeight) - TopBorder)
  EndSelect
  Debug ""
  EndIf
Next

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Panel Top and Bottom Border Size

Post by ChrisR »

With Paint, the Panel border seems to be left=3, top=1, left=5 and bottom=4
Is there a way to get it with GetSystemMetrics or other ?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: Panel Top and Bottom Border Size

Post by RASHAD »

Hi ChrisR
All I can get from PanelGadget()

Code: Select all

OpenWindow(0, 0, 0, 440, 240, "", #PB_Window_SystemMenu)

PanelGadget(0, 20, 20, 400, 200)
AddGadgetItem(0, -1, "Tab 1")
CloseGadgetList()
SetWindowLongPtr_( GadgetID(0), #GWL_STYLE, GetWindowLongPtr_( GadgetID(0), #GWL_STYLE )|#TCS_FIXEDWIDTH ) 
SendMessage_( GadgetID(0), #TCM_SETITEMSIZE, 0, 100|40<<16) ;Change tab height to 40
SendMessage_( GadgetID(0), #TCM_ADJUSTRECT,0,r.RECT)

;Tab dim.
Debug r\left
Debug r\top
Debug r\right
Debug r\bottom

;Panel outer dim.
GetWindowRect_(GadgetID(0),gr.RECT)
Debug gr\left
Debug gr\top
Debug gr\right
Debug gr\bottom

;Panel inner dim.
GetClientRect_(GadgetID(0),cr.RECT)
Debug cr\left
Debug cr\top
Debug cr\right
Debug cr\bottom


Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Egypt my love
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Panel Top and Bottom Border Size

Post by ChrisR »

Hi RASHAD,
Thanks for the example, even if it doesn't really answer
I've browsed the Tab Control Messages and the Tab Control Macros but I didn't see anything about the borders!

I think I'm going to hard-code the Panel borders size with: left=3, top=1, left=5 and bottom=4
BarryG
Addict
Addict
Posts: 3318
Joined: Thu Apr 18, 2019 8:17 am

Re: Panel Top and Bottom Border Size

Post by BarryG »

ChrisR wrote:I think I'm going to hard-code the Panel borders size
Never do this! Your code may look okay for you, but it won't for others.

I can help, but I don't know what you're trying to do. Please explain clearer.
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Panel Top and Bottom Border Size

Post by ChrisR »

I know and I'd like to avoid if possible
I've spent a lot of time googling but no results so far..

I play a little bit with WM_PRINT and I need to know the offset of a Gadget in x=0, y=0, inside a container to draw Gadgets children at the right position
With GetWindowRect and GetClientRect it looks good for Window, Container, ScrollArea, Canvas_container but not with the Panel.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: Panel Top and Bottom Border Size

Post by RASHAD »

Change the border of the container to see the result

Code: Select all

OpenWindow(0, 0, 0, 440, 240, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ContainerGadget(0,10,10,420,220,#PB_Container_Double)
  PanelGadget(1, 10, 10, 400, 200)
    AddGadgetItem(1, -1, "Tab 1")
  CloseGadgetList()
CloseGadgetList()

xoffset = GadgetX(1,#PB_Gadget_ScreenCoordinate)-GadgetX(0,#PB_Gadget_ScreenCoordinate)
yoffset = GadgetY(1,#PB_Gadget_ScreenCoordinate)-GadgetY(0,#PB_Gadget_ScreenCoordinate)
Debug xoffset
Debug yoffset


Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Egypt my love
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Panel Top and Bottom Border Size

Post by ChrisR »

All good, that's the right way 8)
It is the offset for the Container in your example
But by doing it in the same way, it is also good for the Panel:

Code: Select all

OpenWindow(0, 0, 0, 440, 240, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
PanelGadget(0, 0, 0, 400, 200)
  AddGadgetItem(0, -1, "Tab 1")
  CanvasGadget(1, 0, 0, 100, 40)
  If StartDrawing(CanvasOutput(1))
    Box(0, 0, 100, 40, $0000FF)
    StopDrawing()
  EndIf
CloseGadgetList()

xoffset = GadgetX(1,#PB_Gadget_ScreenCoordinate)-GadgetX(0,#PB_Gadget_ScreenCoordinate)
yoffset = GadgetY(1,#PB_Gadget_ScreenCoordinate)-GadgetY(0,#PB_Gadget_ScreenCoordinate)
Debug xoffset
Debug yoffset
Debug GetGadgetAttribute(0, #PB_Panel_TabHeight) - yoffset

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
I was looking in a more complicated way without thinking for a second to #PB_Gadget_ScreenCoordinate :oops:
To be done in an invisible window, in my case, to be used then outside of the GadgetList.
Thanks :)
Post Reply