LB Booster
Programming >> Liberty BASIC language >> Show and hide window
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1498341645

Show and hide window
Post by flotulopex on Jun 24th, 2017, 10:00pm

Hi,

I'm having difficulties making a window (sidebar "Side") appear over a first one (background "Back").

I'm trying to display any background image and when my mouse almost touches the right screen edge, a blue "sidebar" will appear.

Unfortunately, it works only one time (the first time after the program is run); afterwards, it will display a white sidebar.

There might be a "simple way" to show and/or hide a window...or does it have to be open/closed every time it is used?

This is my code I simplified for this thread and it will not run with LB but it will with LBB(!).

Code:
' TwoWindows.bas

NOMAINWIN

GRAPHICBOX #Main.GBx1,0,0,1920,1080
STYLEBITS  #Main.GBx1,0,_WS_BORDER,0,0
GRAPHICBOX #Side.GBx1,0,0,200,1080
STYLEBITS  #Side.GBx1,0,_WS_BORDER,0,0

[MAIN]
   WindowWidth  = 1920
   WindowHeight = 1080
   LOADBMP "Back", DefaultDir$ + "\" + "BACK.bmp" '1920x1080 bmp file
   OPEN "BACK" FOR window_popup AS #Main
   #Main "TRAPCLOSE [QuitMain]"
   #Main.GBx1 "down"
   #Main.GBx1 "drawbmp Back 0 0"
   #Main.GBx1 "when leftButtonDown [MouseLeftButton]"
   #Main.GBx1 "when mouseMove [MouseMove]"
   WAIT

[QuitMain]
   CLOSE #Main
   END

[SIDE]
   UpperLeftX   = 1720
   UpperLeftY   = 0
   WindowWidth  = 200
   WindowHeight = 1080
   LOADBMP "Side", DefaultDir$ + "\" + "SIDE.bmp" '200x1080 bmp file
   OPEN "SIDE" FOR window_popup AS #Side
   #Side "TRAPCLOSE [QuitSide]"
   #Side.GBx1 "down"
   #Side.GBx1 "drawbmp Side 0 0"
   WAIT

[QuitSide]
   CLOSE #Side
   WAIT

[MouseLeftButton]
   IF (MouseX < 10 AND MouseY < 10) THEN GOTO [QuitMain] 'clic on top left = QUIT
   WAIT

[MouseMove]
   IF MouseX > 1900 THEN GOTO [SIDE] 'open "SIDE"
   IF MouseX < 1720 THEN GOTO [QuitSide] 'close "SIDE"
   WAIT 


Any idea what I'm doing wrong?
Re: Show and hide window
Post by Richard Russell on Jun 24th, 2017, 11:21pm

on Jun 24th, 2017, 10:00pm, flotulopex wrote:
There might be a "simple way" to show and/or hide a window...or does it have to be open/closed every time it is used?

I think you can use the 'show' and 'hide' GUI commands with a window as well as with a control. Something like this might work:

Code:
[MouseMove]
   IF MouseX > 1900 THEN #Side "show"
   IF MouseX < 1720 THEN #Side "hide"
   WAIT 

Richard.
Re: Show and hide window
Post by Richard Russell on Jun 25th, 2017, 09:30am

on Jun 24th, 2017, 11:21pm, Richard Russell wrote:
I think you can use the 'show' and 'hide' GUI commands with a window as well as with a control.

Here's your entire program adapted accordingly; it seems to work for me. I've commented out the LOADBMP statements because I don't have your bitmaps; instead I've filled the 'side' window with red to make it visible:

Code:
' TwoWindows.bas

NOMAINWIN

GRAPHICBOX #Main.GBx1,0,0,DisplayWidth,DisplayHeight
STYLEBITS  #Main.GBx1,0,_WS_BORDER,0,0
GRAPHICBOX #Side.GBx1,0,0,200,DisplayHeight
STYLEBITS  #Side.GBx1,0,_WS_BORDER,0,0

[MAIN]
   WindowWidth  = DisplayWidth
   WindowHeight = DisplayHeight
   ' LOADBMP "Back", DefaultDir$ + "\" + "BACK.bmp" 'DisplayWidthxDisplayHeight bmp file
   OPEN "BACK" FOR window_popup AS #Main
   #Main "TRAPCLOSE [QuitMain]"
   #Main.GBx1 "down"
   #Main.GBx1 "drawbmp Back 0 0"
   #Main.GBx1 "when leftButtonDown [MouseLeftButton]"
   #Main.GBx1 "when mouseMove [MouseMove]"

   UpperLeftX   = DisplayWidth-200
   UpperLeftY   = 0
   WindowWidth  = 200
   WindowHeight = DisplayHeight
   'LOADBMP "Side", DefaultDir$ + "\" + "SIDE.bmp" '200xDisplayHeight bmp file
   STYLEBITS #Side,0,_WS_VISIBLE,0,0
   OPEN "SIDE" FOR window_popup AS #Side
   #Side.GBx1 "down; fill red"
   #Side.GBx1 "drawbmp Side 0 0"
   WAIT

[QuitMain]
   CLOSE #Main
   CLOSE #Side
   END
   
[MouseLeftButton]
   IF (MouseX < 10 AND MouseY < 10) THEN GOTO [QuitMain] 'clic on top left = QUIT
   WAIT

[MouseMove]
   IF MouseX > DisplayWidth-20 THEN #Side "show"
   IF MouseX < DisplayWidth-200 THEN #Side "hide"
   WAIT 

Richard.
Re: Show and hide window
Post by flotulopex on Jun 25th, 2017, 10:16am

Thanks a lot Richard. It works effectively.

I spent all my Saturday afternoon searching for this (...).

Thank you again wink
Re: Show and hide window
Post by flotulopex on Jun 25th, 2017, 10:39am

BTW, where can I find info about the _WS_VISIBLE stylebit?

I can't find it in the help file.

These area the ones listed in the help file:
_WS_BORDER Creates a window that has a thin-line border.
_WS_CAPTION Creates a window that has a title bar (includes the WS_BORDER style).
_WS_HSCROLL Creates a window that has a horizontal scroll bar.
_WS_MAXIMIZE Creates a window that is initially maximized.
_WS_MAXIMIZEBOX Creates a window that has a Maximize button.
_WS_MINIMIZE Creates a window that is initially minimized. Same as the WS_ICONIC style.
_WS_MINIMIZEBOX Creates a window that has a Minimize button.
_WS_VSCROLL Creates a window that has a vertical scroll bar.
Re: Show and hide window
Post by Richard Russell on Jun 25th, 2017, 11:20am

on Jun 25th, 2017, 10:39am, flotulopex wrote:
BTW, where can I find info about the _WS_VISIBLE stylebit?

MSDN has a list of style bits here, including that one.

I'm not sure it is strictly necessary in your program, but I wanted to avoid the side window initially appearing, even if only for a brief 'flash'.

Richard.

Re: Show and hide window
Post by flotulopex on Jun 25th, 2017, 3:35pm

Quote:
I wanted to avoid the side window initially appearing, even if only for a brief 'flash'.

This is just perfect! Looks much more "pro".

Thanks again.

Rog'