PureRESIZE library : gadget automatic resizing and more

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

PureRESIZE library : gadget automatic resizing and more

Post by gnozal »

PureRESIZE library V6.2x (MAR 22th 2013)

Purpose

Code: Select all

Automatically resizing gadgets, monitoring window size and position
Functions
http://gnozal.ucoz.com/PureRESIZE_.htm

Example

Code: Select all

If OpenWindow(0, 0, 0, 500, 300, #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered, "Mini-Browser")
  CreateGadgetList(WindowID())
  ButtonGadget(1, 0, 0, 50, 25, "Back")
  ButtonGadget(2, 50, 0, 50, 25, "Next")
  ButtonGadget(3, 100, 0, 50, 25, "Stop")
  StringGadget(4, 150, 3, 325, 20, "C:\Program Files\Nvu\gnozal\index.html")
  ButtonGadget(5, 475, 0, 25 , 25, "Go")
  Frame3DGadget(6, 1, 30, 500, 2, "", 2)
  If WebGadget(10, 5, 35, 490, 260, "") = 0
    MessageRequester("Error", "ATL.dll not found", 0)
    End
  EndIf
  AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
  ; Define callback
  SetWindowCallback(@WindowCallBack())
  ; Set window minimum size
  PureRESIZE_SetWindowMinimumSize(0, 450, 250)
  ; Set gadget resize options
  PureRESIZE_SetGadgetResize(4, #True, #True, #True, #False)
  PureRESIZE_SetGadgetResize(5, #False, #True, #True, #False)
  PureRESIZE_SetGadgetResize(6, #True, #True, #True, #False)
  PureRESIZE_SetGadgetResize(10, #True, #True, #True, #True)

  ;PureRESIZE_SetWindowMonitoring(0, #PureRESIZE_Monitoring_DontMove)
  ;PureRESIZE_SetWindowMonitoring(0, ~#PureRESIZE_Monitoring_DontMove)
  ;PureRESIZE_SetWindowMonitoring(0, #PureRESIZE_Monitoring_DontResize)
  ;PureRESIZE_SetWindowMonitoring(0, ~#PureRESIZE_Monitoring_DontResize)

  ; Envent loop
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Gadget
        Select EventGadgetID()
          Case 1
            SetGadgetState(10, #PB_Web_Back)
          Case 2
            SetGadgetState(10, #PB_Web_Forward)
          Case 3
            SetGadgetState(10, #PB_Web_Stop)
          Case 5
            SetGadgetText(10, GetGadgetText(4))
        EndSelect
      Case #PB_Event_Menu
        SetGadgetText(10, GetGadgetText(4))
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf
Download
Only available for Purebasic Windows x86
PB3.94 : http://gnozal.ucoz.com/PureRESIZE.zip
PB4.0x-4.20 : http://gnozal.ucoz.com/PureRESIZE_.zip
PB4.3x : http://gnozal.ucoz.com/PureRESIZE_430.zip
PB4.4x : http://gnozal.ucoz.com/PureRESIZE_440.zip
PB4.5x : http://gnozal.ucoz.com/PureRESIZE_450.zip
PB4.6x : http://gnozal.ucoz.com/PureRESIZE_460.zip
PB5.0x : http://gnozal.ucoz.com/PureRESIZE_500.zip
PB5.1x : http://gnozal.ucoz.com/PureRESIZE_510.zip

Other libs and tools at http://gnozal.ucoz.com/
Last edited by gnozal on Tue Aug 18, 2009 11:48 am, edited 30 times in total.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

i tried and it works very well.

please, Minimum size of window is usefull, Maximum size also...
in my project i use :

Code: Select all

Global MiniX,MiniY,MaxiX,MaxiY

MiniX = 150
MiniY = 150
MaxiX = GetSystemMetrics_(#SM_CXSCREEN)
MaxiY = 150

Procedure GUI_CB(WindowID,Message,wParam,lParam)
  
  Result = #PB_ProcessPureBasicEvents
  
  Select Message
    
    Case #WM_GETMINMAXINFO
      *pMinMax.MINMAXINFO=lParam
      *pMinMax\ptMinTrackSize\x=MiniX
      *pMinMax\ptMinTrackSize\y=MiniY
      *pMinMax\ptMaxTrackSize\x=MaxiX
      *pMinMax\ptMaxTrackSize\y=MaxiY
      Result = #Null
  EndSelect
  
  ProcedureReturn PureRESIZE_CallBack(WindowID,Message,wParam,lParam,Result)
  
EndProcedure 

If OpenWindow(0,0,0,350,150,#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered,"Test")
  If CreateGadgetList(WindowID(0))
    Frame3DGadget(0,5,5,340,140,"",#PB_Frame3D_Single)
    PureRESIZE_SetGadgetResize(0,#True,#True,#True,#True)
    SetWindowCallback(@GUI_CB())
    Repeat : Until WaitWindowEvent()=#wm_close
  EndIf
EndIf
So description function like that :

PureRESIZE_SetWindowMaximumSize(WindowId.l,Width.w,Height.w)
; With Width = -1 : GetSystemMetrics_(#SM_CXSCREEN)
; With Height = -1 : GetSystemMetrics_(#SM_CYSCREEN)

thanx for advance
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

bug

doesn't work on panel gadget

here is a GUI test :

Code: Select all

Procedure GUI_CB(WindowID,Message,wParam,lParam)
  Result=#PB_ProcessPureBasicEvents
  Result=PureRESIZE_CallBack(WindowID,Message,wParam,lParam,Result)
  ProcedureReturn Result
EndProcedure 

Enumeration
  #gFrame
  #gPanel
  #gPanelB1
  #gPanelB2
  #gContainer
  #gContainerB1
EndEnumeration

OpenWindow(0, 303, 182, 347, 300, #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered,"")
CreateGadgetList(WindowID(0))
Frame3DGadget(#gFrame, 5, 5, 335, 75, "Frame3D Gadget", #PB_Frame3D_Single)
PanelGadget(#gPanel, 5, 85, 335, 100)
AddGadgetItem(#gPanel,-1,"Panel Gadget - 1")
ButtonGadget(#gPanelB1,5,5,320,22,"Button inside Panel Gadget - 1")
AddGadgetItem(#gPanel,-1,"Panel Gadget - 2")
ButtonGadget(#gPanelB2,5,5,320,22,"Button inside Panel Gadget - 2")
CloseGadgetList()
ContainerGadget(#gContainer,5,190,335,105,#PB_Container_Flat)
ButtonGadget(#gContainerB1,5,5,325,95,"Button inside Container Gadget")
CloseGadgetList()

PureRESIZE_SetGadgetResize(#gFrame, #True, #True, #True, #False) 
PureRESIZE_SetGadgetResize(#gPanel, #True, #True, #True, #True) 
PureRESIZE_SetGadgetResize(#gContainer, #True, #True, #True, #True) 
PureRESIZE_SetGadgetResize(#gContainerB1, #True, #True, #True, #True) 

SetWindowCallback(@GUI_CB())

Repeat : Until WaitWindowEvent()=#PB_EventCloseWindow

End
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Library update

- some fixes
- renamed functions
- new functions
bug
doesn't work on panel gadget
I will take a look. Thanks for your report.

Please note : I didn't mean to offend anybody with this lib !
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

Post by USCode »

gnozal,
I think the RESIZE code, along with your additional procedures, packaged as a PB library will be very useful to many folks - thanks again.
The only thing they need to be aware of is that it is platform-specific to Windows with the callback.
Perhaps sometime, when I can find the time, I'll package my cross-platform ReSize code as a PB library as well. But right now using the source code isn't too difficult.
:D
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Library update

- fixed PanelGadget not resizing

But, there is a strange incompatibility (interference ?) between PanelGadget and ContainerGadget. Will be fixed soon.
Last edited by gnozal on Wed Dec 15, 2004 8:36 am, edited 1 time in total.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Library update

Should now work for all gadgets

- fixed PureContainer / PanelGadget interference (the code example below now works)

It seems that PureContainer requires the callback to handle #WM_SIZE and #WM_SIZING messages (for all others gadgets, handling #WM_SIZE only seems enough).

Example :

Code: Select all

Procedure GUI_CB(WindowId,Message,wParam,lParam)
  Result=#PB_ProcessPureBasicEvents
  Result=PureRESIZE_CallBack(WindowId,Message,wParam,lParam,Result)
  ProcedureReturn Result
EndProcedure

Enumeration
  #gFrame
  #gPanel
  #gPanelB1
  #gPanelB2
  #gContainer
  #gContainerB1
EndEnumeration

OpenWindow(0, 303, 182, 347, 300, #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered,"")
CreateGadgetList(WindowID(0))
Frame3DGadget(#gFrame, 5, 5, 335, 75, "Frame3D Gadget", #PB_Frame3D_Single)
PanelGadget(#gPanel, 5, 85, 335, 100)
AddGadgetItem(#gPanel,-1,"Panel Gadget - 1")
ButtonGadget(#gPanelB1,5,5,320,22,"Button inside Panel Gadget - 1")
AddGadgetItem(#gPanel,-1,"Panel Gadget - 2")
ButtonGadget(#gPanelB2,5,5,320,22,"Button inside Panel Gadget - 2")
CloseGadgetList()
ContainerGadget(#gContainer,5,190,335,105,#PB_Container_Flat)
ButtonGadget(#gContainerB1,5,5,325,95,"Button inside Container Gadget")
CloseGadgetList()

PureRESIZE_SetGadgetResize(#gFrame, #True, #True, #True, #False)
PureRESIZE_SetGadgetResize(#gPanel, #True, #True, #True, #False)
PureRESIZE_SetGadgetResize(#gPanelB1, #True, #True, #True, #False)
PureRESIZE_SetGadgetResize(#gPanelB2, #True, #True, #True, #False)
PureRESIZE_SetGadgetResize(#gContainer, #True, #True, #True, #True)
PureRESIZE_SetGadgetResize(#gContainerB1, #True, #True, #True, #True)

SetWindowCallback(@GUI_CB())

Repeat : Until WaitWindowEvent()=#PB_EventCloseWindow

End
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

good news 8)
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

hi, hope christmas was good.
I'm coming back with a little but annoying bug.

In the example bellow, when the user maximize the window by clicking in the system menu, the new size is not detected.

Code: Select all

; ---------------------------------------------
;            PureRESIZE test file 2
; ---------------------------------------------
;
Procedure GUI_CB(WindowId,Message,wParam,lParam) 
  Result=#PB_ProcessPureBasicEvents 
  Result=PureRESIZE_CallBack(WindowId,Message,wParam,lParam,Result) 
  ProcedureReturn Result 
EndProcedure 

Enumeration 
  #gFrame 
  #gPanel 
  #gPanelB1 
  #gPanelB2 
  #gContainer 
  #gContainerB1 
EndEnumeration 

OpenWindow(0, 303, 182, 347, 300, #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered,"") 
CreateGadgetList(WindowID(0)) 
Frame3DGadget(#gFrame, 5, 5, 335, 75, "Frame3D Gadget", #PB_Frame3D_Single) 
PanelGadget(#gPanel, 5, 85, 335, 100) 
AddGadgetItem(#gPanel,-1,"Panel Gadget - 1") 
ButtonGadget(#gPanelB1,5,5,320,22,"Button inside Panel Gadget - 1") 
AddGadgetItem(#gPanel,-1,"Panel Gadget - 2") 
ButtonGadget(#gPanelB2,5,5,320,22,"Button inside Panel Gadget - 2") 
CloseGadgetList() 
ContainerGadget(#gContainer,5,190,335,105,#PB_Container_Flat) 
ButtonGadget(#gContainerB1,5,5,325,95,"Button inside Container Gadget") 
CloseGadgetList() 

PureRESIZE_SetGadgetResize(#gFrame, #True, #True, #True, #False) 
PureRESIZE_SetGadgetResize(#gPanel, #True, #True, #True, #False) 
PureRESIZE_SetGadgetResize(#gPanelB1, #True, #True, #True, #False) 
PureRESIZE_SetGadgetResize(#gPanelB2, #True, #True, #True, #False) 
PureRESIZE_SetGadgetResize(#gContainer, #True, #True, #True, #True) 
PureRESIZE_SetGadgetResize(#gContainerB1, #True, #True, #True, #True) 

SetWindowCallback(@GUI_CB()) 

Repeat : Until WaitWindowEvent()=#PB_EventCloseWindow 

End 
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

You are right... :cry: It works for example 1 but not for example 2. It's a gadget inside gadget thing ...
I probably forgot something in the callback ; I will take a look.
Thanks for the report.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Library update
- fixed PureContainer not resizing after a WM_MOVE event (this gadget really does not behave like the others)
- help is now CHM

Please report any bugs.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

hummm, the bug is corrected for the source example, but not for my program.
my source includes many gadgets ( over 50... ).
i'm trying to locate with precision the problem and i'll tell you in which case it happens.

more i'll appreciate if you can include this function :
PureResize_SetWindowMaximumSize(WindowNumber.l, MaximumWidth.l, MaximumHeight.l)

or
PureResize_SetWindowSize(WindowNumber.l, MinimumWidth.l, MinimumHeight.l, MaximumWidth.l, MaximumHeight.l))

based on this code for example :

Code: Select all

;-
;- PART 1 - RESIZE STUFF
;-

Structure RESIZE_WindowStruct
  
  Handle.l      ; Handle of Window
  MinWidth.w    ; Minimum width
  MinHeight.w   ; Minimum height
  MaxWidth.w    ; Maximum width
  MaxHeight.w   ; Maximum height
  
EndStructure

NewList RESIZE_Window.RESIZE_WindowStruct()

Procedure.b RESIZE_SetWindow(Window.l,MinWidth.w,MinHeight.w,MaxWidth.w,MaxHeight.w)
  
  Protected Window.l,MinWidth.w,MinHeight.w,MaxWidth.w,MaxHeight.w
  
  If AddElement(RESIZE_Window()) = #False
    ProcedureReturn #False
  EndIf
  
  If MaxWidth = -1
    MaxWidth = GetSystemMetrics_(#SM_CXSCREEN)
  EndIf
  
  If MaxHeight = -1
    MaxHeight = GetSystemMetrics_(#SM_CYSCREEN)
  EndIf
  
  RESIZE_Window()\Handle    = WindowID(Window)
  RESIZE_Window()\MinWidth  = MinWidth
  RESIZE_Window()\MinHeight = MinHeight
  RESIZE_Window()\MaxWidth  = MaxWidth
  RESIZE_Window()\MaxHeight = MaxHeight
  
  ProcedureReturn #True
  
EndProcedure

Procedure RESIZE_Callback(WindowID,Message,wParam,lParam,Result)
  
  If (Message=#WM_GETMINMAXINFO)
    
    ForEach RESIZE_Window()
      
      If RESIZE_Window()\Handle = WindowID
        
        *rs_MinMax.MINMAXINFO = lParam
        *rs_MinMax\ptMinTrackSize\x = RESIZE_Window()\MinWidth
        *rs_MinMax\ptMinTrackSize\y = RESIZE_Window()\MinHeight
        *rs_MinMax\ptMaxTrackSize\x = RESIZE_Window()\MaxWidth
        *rs_MinMax\ptMaxTrackSize\y = RESIZE_Window()\MaxHeight
        
        ProcedureReturn #Null
        
      EndIf
      
    Next
    
  EndIf
  
  ProcedureReturn Result
  
EndProcedure

;-
;- PART 2 - TEST EXAMPLE
;-

Procedure GUI_CB(WindowID,Message,wParam,lParam) 
  
  Result = #PB_ProcessPureBasicEvents 
  Result = RESIZE_Callback(WindowID,Message,wParam,lParam,Result) 
  ProcedureReturn Result
  
EndProcedure 

OpenWindow(0,0,0,320,240,#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered,"rs_lib Test") 

RESIZE_SetWindow(0,220,140,420,340)
;RESIZE_SetWindow(0,220,140,-1,-1)

SetWindowCallback(@GUI_CB()) 

Repeat : Until WaitWindowEvent()=#PB_EventCloseWindow 

End
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Flype wrote:hummm, the bug is corrected for the source example, but not for my program.
my source includes many gadgets ( over 50... ).
i'm trying to locate with precision the problem and i'll tell you in which case it happens.
Thanks, I can't fix it if I don't have an example.
Have you tried to call the PureRESIZE_SetGadgetResize() functions in a different order ?
for example :
PureRESIZE_SetGadgetResize(#gContainerB1, #True, #True, #True, #True)
PureRESIZE_SetGadgetResize(#gContainer, #True, #True, #True, #True)
instead of :
PureRESIZE_SetGadgetResize(#gContainer, #True, #True, #True, #True)
PureRESIZE_SetGadgetResize(#gContainerB1, #True, #True, #True, #True)
The gadgets are resized in the same order in the callback, so it could explain some 'bugs' ? Maybe I should resize the 'container gadgets' like panel / container before the gadgets ? Any idea ?
Flype wrote:more i'll appreciate if you can include this function :
PureResize_SetWindowMaximumSize(WindowNumber.l, MaximumWidth.l, MaximumHeight.l)
Ok, I will add this.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

yes you are right, in a specific order, it works but it's becoming a little bit tricky as long as my source code grows...

thanx for adding the Maximize function. :wink:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Flype wrote:yes you are right, in a specific order, it works but it's becoming a little bit tricky as long as my source code grows...
Could you provide some code ?
All my test programs run well.
Last edited by gnozal on Sat Jan 29, 2005 12:56 pm, edited 1 time in total.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Post Reply