Page 1 of 1

Resize Window Client Area Dynamically (Windows)

Posted: Tue Feb 07, 2017 7:52 pm
by RASHAD
Very simple (For standard position of ToolBar & StatusBar) :wink:

Code: Select all

Global cMBH,cTBH,cSBH

Procedure sizeCB()
  ResizeGadget(0,#PB_Ignore,cTBH,WindowWidth(0),WindowHeight(0)-cMBH-cTBH-cSBH)
EndProcedure

OpenWindow(0,0,0,400,300,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered| #PB_Window_MaximizeGadget| #PB_Window_SizeGadget)

 If CreateMenu(0, WindowID(0))
    MenuTitle("File")
      MenuItem( 1, "&Load...")
      MenuItem( 2, "Save")
      MenuItem( 3, "Save As...")
      MenuBar()
      OpenSubMenu("Recents")
        MenuItem( 5, "Pure.png")
        MenuItem( 6, "Basic.jpg")
        OpenSubMenu("Even more !")
          MenuItem( 12, "Yeah")
        CloseSubMenu()
        MenuItem( 13, "Rocks.tga")
      CloseSubMenu()
      MenuBar()
      MenuItem( 7, "&Quit")

    MenuTitle("Edition")
      MenuItem( 8, "Cut")
      MenuItem( 9, "Copy")
      MenuItem(10, "Paste")
      
    MenuTitle("?")
      MenuItem(11, "About")
  EndIf
  
  MBH = MenuHeight()
  cMBH = MBH
    
  If CreateToolBar(0, WindowID(0))
    ToolBarStandardButton(0, #PB_ToolBarIcon_New)
    ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
    ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
  EndIf  
   
  SendMessage_(ToolBarID(0),#TB_GETRECT,0,r.RECT)
  pad = SendMessage_(ToolBarID(0),#TB_GETPADDING,0,0)
  TBH = r\bottom-r\top + pad >> 16
  cTBH = TBH
  
  If CreateStatusBar(0, WindowID(0))
    AddStatusBarField(100)
    AddStatusBarField(50)
    AddStatusBarField(100)
  EndIf

  StatusBarText(0, 0, "Area 1")
  StatusBarText(0, 1, "Area 2", #PB_StatusBar_BorderLess)
  StatusBarText(0, 2, "Area 3", #PB_StatusBar_Right | #PB_StatusBar_Raised)
  
  SendMessage_(StatusBarID(0),#SB_GETRECT,0,r.RECT)
  Dim pad(2)
  SendMessage_(StatusBarID(0),#SB_GETBORDERS,0,@pad())
  SBH = r\bottom-r\top + pad(1)
  cSBH = SBH
  
  ContainerGadget(0,0,TBH,400,300-TBH-SBH-25, #PB_Container_Flat)
    ButtonGadget(1,5,5,80,24,"Toggle Menu")
    ButtonGadget(2,90,5,80,24,"Toggle ToolBar")
    ButtonGadget(3,175,5,90,24,"Toggle StatusBar")
  CloseGadgetList()
  
  BindEvent(#PB_Event_SizeWindow,@sizeCB())
  
Repeat
           
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1       
      
      Case #PB_Event_Menu
          Select EventMenu()
           Case 1            
          EndSelect
      
      Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              mRun ! 1
              If mRun = 1
                SetMenu_(WindowID(0),0)
                cMBH = 0
              Else
                SetMenu_(WindowID(0),MenuID(0))
                cMBH = MBH
              EndIf              
              ResizeGadget(0,#PB_Ignore,cTBH,WindowWidth(0),WindowHeight(0)-cMBH-cTBH-cSBH)
              
            Case 2
              tRun ! 1
              If tRun = 1
                ShowWindow_(ToolBarID(0),#SW_HIDE)
                cTBH = 0
              Else
                ShowWindow_(ToolBarID(0),#SW_SHOW)
                cTBH = TBH
              EndIf
              ResizeGadget(0,#PB_Ignore,cTBH,WindowWidth(0),WindowHeight(0) - cMBH-cTBH-cSBH)
              
            Case 3
              sRun ! 1
              If sRun = 1
                ShowWindow_(StatusBarID(0),#SW_HIDE)
                cSBH = 0
              Else
                ShowWindow_(StatusBarID(0),#SW_SHOW)
                cSBH = SBH
              EndIf
              ResizeGadget(0,#PB_Ignore,cTBH,WindowWidth(0),WindowHeight(0)-cMBH-cTBH-cSBH)
          EndSelect          

  EndSelect 

Until Quit = 1
End

Re: Resize Window Client Area Dynamically (Windows)

Posted: Wed Feb 08, 2017 7:48 pm
by Damion12
Nice and fast!

Re: Resize Window Client Area Dynamically (Windows)

Posted: Thu Feb 09, 2017 2:21 pm
by Kwai chang caine
Thanks for sharing 8)

Re: Resize Window Client Area Dynamically (Windows)

Posted: Thu Feb 09, 2017 3:51 pm
by skywalk
Thanks RASHAD 8)

Re: Resize Window Client Area Dynamically (Windows)

Posted: Thu Feb 09, 2017 4:01 pm
by Fred
:shock: You should have seen my code... Thanks for a nice solution for those who want these !

Re: Resize Window Client Area Dynamically (Windows)

Posted: Thu Feb 09, 2017 4:58 pm
by davido
@RASHAD,
Very nice, thank you for sharing. 8)