Page 1 of 1

Hiding a windowed screen

Posted: Wed May 19, 2004 3:37 pm
by tinman
Hello,

Does anyone know how to hide a windowed screen? I need something like the HideGadget() command, but haven't been able to figure it out or find anything on the forums about this.

This is as far as I have got so far, although the problem is that ScreenID() returns the same value as WindowID(). Any suggestions would be most welcome.

Thanks.

Code: Select all

If InitSprite()=0 : End : EndIf

If OpenWindow(0, 0, 0, 400, 350, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar, "")
    If CreateGadgetList(WindowID())
        ButtonGadget(1, 10, 310, 380, 30, "Show/hide")
    EndIf
    
    If OpenWindowedScreen(WindowID(), 0, 0, 400, 300, 0, 0, 50)
        wid.l = WindowID()
        Debug wid
        
        sid.l = ScreenID()
        Debug sid
        
        SetFrameRate(60)
        StartDrawing(ScreenOutput())
        
        gtc.l = GetTickCount_()
        RandomSeed(gtc)
        For i.l=1 To 100000
            Plot(Random(399), Random(299), RGB(Random(255),Random(255),Random(255)))
        Next
        StopDrawing()
    EndIf

    Repeat
        ev = WaitWindowEvent()
        
        While ev
            Select ev
                Case #PB_Event_Gadget
                    show_hide = 1 - show_hide
                    If show_hide
                        ; hide
                        ShowWindow_(sid, SW_HIDE)
                    Else
                        ; show
                        ShowWindow_(sid, SW_SHOW)
                    EndIf
                    
                Case #PB_Event_Repaint
                    FlipBuffers()
                    FlipBuffers()
                    
                Case #PB_Event_CloseWindow
                    quit = 1
            EndSelect
            
            ev = WindowEvent()
        Wend
    Until quit=1
EndIf
End

Posted: Wed May 19, 2004 5:06 pm
by fweil
tinman,

This is the way I would do more or less, using minimize instead of hide which makes the window not visible, but as it is not visible, it is also not possible to click anything to toggle hide state.

Code: Select all

  #Button_Minimize = 1
  If InitSprite()
      If OpenWindow(0, 0, 0, 400, 350, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar, "") 
          If CreateGadgetList(WindowID()) 
              ButtonGadget(#Button_Minimize, 10, 310, 380, 30, "Show/hide") 
          EndIf 
          If OpenWindowedScreen(WindowID(), 0, 0, 400, 300, 0, 0, 50) 
          SetFrameRate(60) 
          StartDrawing(ScreenOutput()) 
          gtc.l = GetTickCount_() 
          RandomSeed(gtc) 
          For i.l=1 To 100000 
          Plot(Random(399), Random(299), RGB(Random(255),Random(255),Random(255))) 
          Next 
          StopDrawing() 
          EndIf 
          Repeat 
            Select WaitWindowEvent()
              Case #PB_Event_Gadget 
                Select EventGadgetID()
                  Case #Button_Minimize
                    ShowWindow_(WindowID(), #SW_MINIMIZE ) 
                EndSelect
              Case #PB_Event_Repaint 
                FlipBuffers() 
              Case #PB_Event_CloseWindow 
                quit = 1 
            EndSelect 
          Until quit=1 
      EndIf
  EndIf 
End 
Rgrds

Posted: Wed May 19, 2004 5:32 pm
by tinman
You missed the point. I need to hide the screen, not the window. Like HideGadget() would hide a gadget and not the window.

Posted: Wed May 19, 2004 6:01 pm
by fweil
Allright, you need to hide the window. This si OK.

Hide it by using SW_HIDE. It works.

But except by making it visible back from outside, you will never find an event that will turn from hidden to visible from this window itself because it is hidden ... So in case you manage this window from another process you will send messages to no more hide it, otherwise it will never work.

Or maybe you expected to turn the window visible from an internal event, but this is the same situation I describe by doing it from outside. No user input is possible as soon as the window has been hidden.

Rgrds

Posted: Wed May 19, 2004 6:31 pm
by tinman
I do not want to hide the window. I want to hide the screen only! Think of the screen like a gadget. I want a program which does this:

Code: Select all

If OpenWindow(0, 0, 0, 400, 350, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar, "")
    If CreateImage(1, 400, 300)
        StartDrawing(ImageOutput())
        
        gtc.l = GetTickCount_()
        RandomSeed(gtc)
        For i.l=1 To 100000
            Plot(Random(399), Random(299), RGB(Random(255),Random(255),Random(255)))
        Next
        StopDrawing()

        If CreateGadgetList(WindowID())
            ButtonGadget(1, 10, 310, 380, 30, "Show/hide")
            ImageGadget(2, 0, 0, 400, 300, UseImage(1))
            sid = GadgetID(2)
        EndIf
    
    EndIf

    Repeat
        ev = WaitWindowEvent()
        
        While ev
            Select ev
                Case #PB_Event_Gadget
                    show_hide = 1 - show_hide
                    If show_hide
                        ; hide
                        ;ShowWindow_(sid, SW_MINIMIZE)
                        HideGadget(2, 1)
                    Else
                        ; show
                        ;ShowWindow_(sid, SW_NORMAL)
                        HideGadget(2, 0)
                    EndIf
                    
                Case #PB_Event_CloseWindow
                    quit = 1
            EndSelect
            
            ev = WindowEvent()
        Wend
    Until quit=1
EndIf
End
But using a windowed screen instead of an image gadget.

Posted: Wed May 19, 2004 6:42 pm
by fweil
I guess the screen is not a regular object that can support such behaviour. Or may you try to use one trick being to cover the screen part of the window with an image gadget or something like this ...

Posted: Wed May 19, 2004 6:45 pm
by VPureBasic
Hi Tinman.

Try this... it's work great on my side!

Code: Select all

If InitSprite()=0 : End : EndIf 

If OpenWindow(0, 0, 0, 400, 350, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar, "") 
    If CreateGadgetList(WindowID()) 
        ButtonGadget(1, 10, 310, 380, 30, "Show/hide") 
    EndIf 
    
    ;- Add These lines...
    If OpenWindow( 1,0,0,400,300,#PB_Window_Invisible,"" )
         SetWindowLong_( WindowID(1), #GWL_STYLE, #WS_CHILD|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
         SetParent_( WindowID(1), WindowID(0) )
          
         If OpenWindowedScreen(WindowID(1), 0, 0, 400, 300, 0, 0, 50) 
    
               wid.l = WindowID(0) 
               ;Debug wid 
        
               sid.l = WindowID(1)
               ;Debug sid 
        
               SetFrameRate(60) 
               StartDrawing(ScreenOutput()) 
        
               gtc.l = GetTickCount_() 
               RandomSeed(gtc) 
               For i.l=1 To 100000 
                    Plot(Random(399), Random(299), RGB(Random(255),Random(255),Random(255))) 
               Next 
               StopDrawing() 
         EndIf
    EndIf 

    Repeat 
        ev = WaitWindowEvent() 
        
        While ev 
            Select ev 
                Case #PB_Event_Gadget 
                    show_hide = 1 - show_hide 
                    If show_hide 
                        ; hide 
                        HideWindow( 1, 1 ) 
                    Else 
                        ; show 
                        HideWindow( 1, 0 ) 
                    EndIf 
                    
                Case #PB_Event_Repaint 
                    FlipBuffers() 
                    FlipBuffers() 
                    
                Case #PB_Event_CloseWindow 
                    quit = 1 
            EndSelect 
            
            ev = WindowEvent() 
        Wend 
    Until quit=1 
EndIf 
End 
Roger

Posted: Thu May 20, 2004 12:03 pm
by tinman
VPureBasic wrote:Try this... it's work great on my side!
Thanks Roger, neat idea. Works very nicely here too.

Posted: Thu May 20, 2004 5:31 pm
by fsw
In addition to that it would be nice to have more than one screen...
But OpenWindowedScreen returns 1 or 0 and not the handle of the screen.
Would be nice if that would be changed (if possible...)
And ScreenOutput() needs to be changed to, to accept handles like:
ScreenOutput(Screen1)
etc.
and other screen commands should be changed too if needed...

But as I said, don't know if Windows allows it or not 8O

Posted: Thu May 20, 2004 7:11 pm
by fweil
AFAIK, only a single screen can be opened at a time, because it uses all the video ressources, or am I wrong ?

Rgrds

Posted: Thu May 20, 2004 9:30 pm
by fsw
Well, you can have 2 different programs with windowed screen running at the same time, can you not :?:
So it's not a graphic card issue, it's a os or pb issue ... suppose a pb one :(

Posted: Thu May 20, 2004 10:05 pm
by tinman
fsw wrote:Well, you can have 2 different programs with windowed screen running at the same time, can you not :?:
Yep, you can have more than 1 windowed screen in multiple programs...but perhaps there is some OS limit which stops multiple screens in the same program?