Resize Window Client Area Dynamically (Windows)

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Resize Window Client Area Dynamically (Windows)

Post 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
Egypt my love
Damion12
User
User
Posts: 81
Joined: Tue Oct 30, 2012 1:39 am

Re: Resize Window Client Area Dynamically (Windows)

Post by Damion12 »

Nice and fast!
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Resize Window Client Area Dynamically (Windows)

Post by Kwai chang caine »

Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
skywalk
Addict
Addict
Posts: 4219
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Resize Window Client Area Dynamically (Windows)

Post by skywalk »

Thanks RASHAD 8)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred
Administrator
Administrator
Posts: 18243
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Resize Window Client Area Dynamically (Windows)

Post by Fred »

:shock: You should have seen my code... Thanks for a nice solution for those who want these !
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Resize Window Client Area Dynamically (Windows)

Post by davido »

@RASHAD,
Very nice, thank you for sharing. 8)
DE AA EB
Post Reply