I have used PureResize() for a long time, but as the developer seems to have gone silent I'm having to write my own version so I can upgrade to the most recent version of PB.
PureResize has some elegant features that I do not use so this simple alternative is a bare bones alternative.
Comments and reports welcomed
RichardL
Original code 10th May 2014
Revised code 15th May 2014 - No longer needs the 'Window#' to be passed to SetGadgetResize().
I had not realised that GetActiveWindow() would return the Window# immediately it was opened.
Also, added <While WindowEvent() : Wend> after the ResizeGadget() to force the gadget to be re-rendered before the next change is made. The result is much smoother operation, probably at the cost of increased processor load... but it seems to be negligible.
Save this code as 'Resize.pbi'...
Code: Select all
; A basic gadget resizer
Structure RESIZER
WinNum.l
OldWindowHeight.l
OldWindowWidth.l
GadNum.l
FlagX.l
FlagY.l
FlagW.l
FlagH.l
EndStructure
Global NumReSizeGads = 1
Global Dim ReSize.RESIZER(1)
Procedure SetGadgetResize(GadNum,FlagX,FlagY,FlagWidth,FlagHeight)
; Add a gadget to the list of gadgets that are to be re-sized.
If NumReSizeGads > 1
Redim ReSize(NumReSizeGads)
EndIf
GadWin = GetActiveWindow()
With ReSize(NumReSizeGads)
\WinNum = GetActiveWindow()
\OldWindowHeight = WindowHeight(GadWin)
\OldWindowWidth = WindowWidth(GadWin)
\GadNum = GadNum
\FlagX = FlagX & 1
\FlagY = FlagY & 1
\FlagW = FlagWidth & 1
\FlagH = FlagHeight & 1
EndWith
NumReSizeGads + 1
EndProcedure
Procedure WinCallback(Win,msg,wParam,lParam)
Protected dx,dy,FoundWin,n
Protected NewX,NewY,NewW,NewH
Protected Result = #PB_ProcessPureBasicEvents
Select msg
; Window is resized, so adjust gadget positions/size etc
Case #WM_SIZE ;{
FoundWin = #False
For n = 1 To NumReSizeGads-1
If WindowID(ReSize(n)\WinNum) = Win
; How much has window changed?
dy = WindowHeight(ReSize(n)\WinNum) - ReSize(n)\OldWindowHeight
dx = WindowWidth(ReSize(n)\WinNum) - ReSize(n)\OldWindowWidth
; Save the new window size.
ReSize(n)\OldWindowHeight = WindowHeight(ReSize(n)\WinNum)
ReSize(n)\OldWindowWidth = WindowWidth(ReSize(n)\WinNum)
FoundWin = #True
Break
EndIf
Next
; Adjust the gadget sizes / positions
If FoundWin
For n = 1 To NumReSizeGads-1
With ReSize(n)
If WindowID(\WinNum) = Win
NewX = (dx * \FlagX) + GadgetX(\GadNum)
NewY = (dy * \FlagY) + GadgetY(\GadNum)
NewW = (dx * \FlagW) + GadgetWidth(\GadNum)
NewH = (dy * \FlagH) + GadgetHeight(\GadNum)
ResizeGadget(\GadNum,NewX,NewY,NewW,NewH)
While WindowEvent() : Wend
EndIf
EndWith
Next
EndIf
;}
; Example of reading a scroll bar (Vertical)
Case #WM_VSCROLL ;{
If lParam = GadgetID(7)
T = GetGadgetState(7)
SetGadgetText(6,Str(T))
EndIf
;}
; Other callbacks here
EndSelect
ProcedureReturn Result
EndProcedure
Code: Select all
XIncludeFile "Resize.pbi" ; Resize (a) Add gadget to list (b) Manage resizing
; Test code
OpenWindow(1,100,100,200,90,"Re-Size my height",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
SetWindowColor(1,RGB(255,255,0))
WindowBounds(1,200,90,200,400)
; Resize flags are ==========================> (Gadget#,X,Y,W,H)
EditorGadget(1,5,5,190,20) : SetGadgetResize(1,0,0,0,1)
ButtonGadget(2,5,40,190,20,"Button 2") : SetGadgetResize(2,0,1,0,0)
OpenWindow(2,420,100,425,90,"Re-Size Me 2 ways",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
SetWindowColor(2,RGB(0,255,255))
WindowBounds(2,400,90,800,400)
EditorGadget(3,5,5,190,20) : SetGadgetResize(3,0,0,0,1)
EditorGadget(4,200,5,195,20) : SetGadgetResize(4,0,0,1,1)
ButtonGadget(5,5,40,190,40,"Button 4") : SetGadgetResize(5,0,1,0,0)
StringGadget(6,340,65,50,20,"---") : SetGadgetResize(6,1,1,0,0)
ScrollBarGadget(7,400,5,21,80,0,1023,1, #PB_ScrollBar_Vertical) : SetGadgetResize(7,1,0,0,1)
SetGadgetState(7,512)
SetWindowCallback(@WinCallback())
Repeat
; Your event management here
Until WaitWindowEvent() = #PB_Event_CloseWindow