I tried with SendMessage TCM_GETITEMRECT to get the initial width/height of a tab and then, resize it portionally with TCM_SETITEMSIZE.
I'm not really fan of including windows APIs in the generated code, but here, for this case, it seems not too bad.
Code: Select all
EnableExplicit
;- Enumerations
Enumeration Window
#MainWindow
EndEnumeration
Enumeration Gadgets
#Panel_1
#Btn_Button_4
#Btn_Button_5
#Btn_Button_6
#Btn_Button_1
#Btn_Button_2
#Btn_Button_3
EndEnumeration
;- Declare
Declare PropFactorX(X = 0)
Declare PropFactorY(Y = 0)
Declare Resize_MainWindow()
Declare Open_MainWindow(X = 0, Y = 0, Width = 360, Height = 270)
Global WinWidthIni, WinHeightIni
Global Panel_1_WidthIni, Panel_1_HeightIni, Panel_1_TabHeight, Panel_1_TabWidth
Procedure PropFactorX(X = 0)
ProcedureReturn Round(WindowWidth(#MainWindow) * X / WinWidthIni, #PB_Round_Nearest)
EndProcedure
Procedure PropFactorY(Y = 0)
ProcedureReturn Round(WindowHeight(#MainWindow) * Y / WinHeightIni, #PB_Round_Nearest)
EndProcedure
Procedure Resize_MainWindow()
ResizeGadget(#Panel_1, PropFactorX(170), PropFactorY(10), PropFactorX(WinWidthIni - 180), PropFactorY(WinHeightIni - 20))
; Specific for panels and proportional resizing, the tabs must also be resized proportionally and as a result the internal area also
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SendMessage_( GadgetID(#Panel_1), #TCM_SETITEMSIZE, 0, (PropFactorY(Panel_1_TabHeight)<<16) | PropFactorX(Panel_1_TabWidth))
CompilerEndIf
ResizeGadget(#Btn_Button_4, PropFactorX(10), PropFactorY(10), PropFactorX(Panel_1_WidthIni - 30), PropFactorY(Panel_1_HeightIni - 200))
ResizeGadget(#Btn_Button_5, PropFactorX(10), PropFactorY(90), PropFactorX(Panel_1_WidthIni - 30), PropFactorY(Panel_1_HeightIni - 200))
ResizeGadget(#Btn_Button_6, PropFactorX(10), PropFactorY(160), PropFactorX(Panel_1_WidthIni - 30), PropFactorY(Panel_1_HeightIni - 200))
ResizeGadget(#Btn_Button_1, PropFactorX(10), PropFactorY(20), PropFactorX(WinWidthIni - 210), PropFactorY(WinHeightIni - 220))
ResizeGadget(#Btn_Button_2, PropFactorX(10), PropFactorY(100), PropFactorX(WinWidthIni - 210), PropFactorY(WinHeightIni - 220))
ResizeGadget(#Btn_Button_3, PropFactorX(10), PropFactorY(180), PropFactorX(WinWidthIni - 210), PropFactorY(WinHeightIni - 220))
EndProcedure
Procedure Open_MainWindow(X = 0, Y = 0, Width = 360, Height = 270)
If OpenWindow(#MainWindow, X, Y, Width, Height, "Test Porportional Resize", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
PanelGadget(#Panel_1, 170, 10, 180, 250)
AddGadgetItem(#Panel_1, -1, "Tab_0")
ButtonGadget(#Btn_Button_4, 10, 10, 150, 50, "Button_4")
ButtonGadget(#Btn_Button_5, 10, 90, 150, 50, "Button_5")
ButtonGadget(#Btn_Button_6, 10, 160, 150, 50, "Button_6")
AddGadgetItem(#Panel_1, -1, "Tab_1")
CloseGadgetList() ; #Panel_1
ButtonGadget(#Btn_Button_1, 10, 20, 150, 50, "Button_1")
ButtonGadget(#Btn_Button_2, 10, 100, 150, 50, "Button_2")
ButtonGadget(#Btn_Button_3, 10, 180, 150, 50, "Button_3")
WinWidthIni = WindowWidth(#MainWindow) : WinHeightIni = WindowHeight(#MainWindow)
Panel_1_WidthIni = GadgetWidth(#Panel_1) : Panel_1_HeightIni = GadgetHeight(#Panel_1)
; Specific for panels and proportional resizing, the tabs must also be resized proportionally and as a result the internal area also
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Define r.rect
SendMessage_(GadgetID(#Panel_1), #TCM_GETITEMRECT, 0, @r.rect)
Panel_1_TabHeight = r\bottom - r\top : Panel_1_TabWidth = r\right - r\left
CompilerEndIf
BindEvent(#PB_Event_SizeWindow, @Resize_MainWindow(), #MainWindow)
EndIf
EndProcedure
;- Main Program
Open_MainWindow()
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow