Liberty BASIC has a 'locate' command, e.g. print #handle.ext, "locate x y width height" which is used to position/reposition a control within a window or even ouside a window if the control is to be hidden.
Sometimes applications have a group of controls which all need to be hidden at the same time and redisplayed when required to be used. To hide a number of controls and then re-display them, requires a locate command for each control, with the appropriate x, y, width and height parameters. Rather than hide/show each control, it is easier and faster to group the controls together in an area of window which can hidden.
This can be achieved by a single call to user32.dll to resize the window to a height (or width) which will cause the controls to be hidden and later restored to the original size to show the controls again.
In this example, allowance is made for the user having dragged the window around the screen. Before resizing the window, its current x/y co-ords are obtained and used in the 'MoveWindow' message.
Click the Allow Hide checkbox to enable the Hide button. Then click the Hide button and the window will be resized to hide the controls in the bottom panel of the window. The Hide button then becomes a Show button, which when clicked restores the window height bringing twelve of the controls back into view but because the window was narrowed as well and not restored in width, the thirteenth control remains out of view.
Notice also that closing of the window is prevented until the Close button is visible, when the window can be closed either with the Close button or the system menu/buttons in the titlebar.
Button #m1.b3 is drawn with a height of 3 pixels and width of WindowWidth and then disabled, to simulate a divisor bar across the window, below which the controls are grouped. This gives the impression that the controls are positioned on a sliding panel which slides in or out as the window is resized.
'~~~~~~~ Code follows ~~~~~~~~~ if left$(Version$,1)<>"3" then notice "Sorry, LB version 3 only." end end if '~~~~~~~~~~~~~~~~~~~~~~~ display ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dw=DisplayWidth: dh=DisplayHeight WindowWidth=427: WindowHeight=400 UpperLeftX=Int((dw-WindowWidth)/2) UpperLeftY=Int((dh-WindowHeight)/2) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NewHeight=316 'height of window when controls are to be hidden NewWidth=326 'width of window when controls are to be hidden 'struct for the window rectangle params struct Rect,_ x1 as long, y1 as long,_ x2 as long, y2 as long ' allowHide=0 show=1 CR$=chr$(13) ' nomainwin button #m1.b1, "Hide", [hide.show], UL,20,20 button #m1.b2, "Close", [quit], UL,20,330 button #m1.b3, "", , UL,0,290,WindowWidth,3 'button used as graphic button #m1.b4, "1", [null], UL,90,307,20,20 button #m1.b5, "2", [null], UL,110,307,20,20 button #m1.b4, "3", [null], UL,130,307,20,20 button #m1.b5, "4", [null], UL,150,307,20,20 button #m1.b4, "5", [null], UL,170,307,20,20 button #m1.b4, "6", [null], UL,190,307,20,20 button #m1.b5, "7", [null], UL,210,307,20,20 button #m1.b4, "8", [null], UL,230,307,20,20 button #m1.b5, "9", [null], UL,250,307,20,20 button #m1.b4, "0", [null], UL,270,307,20,20 statictext #m1.st1, "", 20,50,200,200 checkbox #m1.cb1, "Allow hide",[test],[test],330,330,75,25 textbox #m1.tb1, 90,330,200,25 open "Hiding controls" for window_nf as #m1 hm1=hwnd(#m1) disable=0: enable=1 'declared var hCb3=hwnd(#m1.b3) 'get handle of button used as a graphic call enableControl hCb3, disable 'disable button used as a graphic #m1, "trapclose [quit]" 'only when close button is visible #m1, "font arial 9" #m1.tb1, "Click checkbox" #m1.st1, "Group controls which need to be hidden into an area of the window ";_ "which can be hidden by reducing the window size.";CR$;CR$;_ "No need to relocate each control outside/inside the window, having to ";_ "ensure the correct x/y locations and control sizes!";CR$;CR$;_ "Allowance is made for the user possibly moving the window." wait ' [null] wait ' [test] allowHide=1-allowHide if allowHide then print #m1.tb1, "Click Hide button" else print #m1.tb1, "Click checkbox" wait ' [quit] 'only if close button is visible if not(show) then wait else close #m1 end end if ' [hide.show] 'resize window to hide or show controls if not(allowHide) then beep:wait show=hideShow(hm1,show,NewWidth,WindowHeight,NewHeight) wait ' sub enableControl hControl, state calldll #user32, "EnableWindow", hControl as long,state as long,result as void end sub function hideShow(h,show,wWidth,wHeight,NewHeight) 'get window co-ords calldll #user32, "GetWindowRect", h as long, Rect as struct, r as void winWidth = Rect.x2.struct - Rect.x1.struct winHeight = Rect.y2.struct - Rect.y1.struct topX = Rect.x1.struct : topY = Rect.y1.struct 'decide window height show=1-show if show then height=wHeight 'window height for panel shown #m1.b1, "Hide" else height=NewHeight 'window height for panel hidden #m1.b1, "Show" end if hideShow=show 'resize window calldll #user32, "MoveWindow", h as long, topX as long, topY as long,_ wWidth as long, height as long, 1 as long, result as void end function '~~~~~~~ End of Code ~~~~~~~~~