Switch between Window and Screen
Posted: Tue Feb 03, 2026 3:35 pm
Hello,
This code snippet is from the PB help.
Is there a way to initially display only the gray interface with buttons, gadgets, and settings options, and then open the OpenWindowedScreen only when a specific button is clicked? Similarly, is there a way to close the screen using KeyboardPushed() and return to the gray interface?
Can OpenWindowedScreen() also be placed above gadgets? Or would you have to hide them first?
Thanks!
This code snippet is from the PB help.
Is there a way to initially display only the gray interface with buttons, gadgets, and settings options, and then open the OpenWindowedScreen only when a specific button is clicked? Similarly, is there a way to close the screen using KeyboardPushed() and return to the gray interface?
Can OpenWindowedScreen() also be placed above gadgets? Or would you have to hide them first?
Thanks!
Code: Select all
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "Can't open the sprite system", 0)
End
EndIf
If OpenWindow(0, 0, 0, 340, 285, "Gadget and sprites!", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(1, 10, 10, 100, 25, "Grab input")
TextGadget (4, 10, 40, 300, 30, "Mouse and keyboard released")
If OpenWindowedScreen(WindowID(0), DesktopScaledX(10), DesktopScaledX(70), DesktopScaledX(320), DesktopScaledX(200), 0, 0, 0)
LoadSprite(0, #PB_Compiler_Home + "examples/sources/Data/PureBasicLogo.bmp")
MouseX = (ScreenWidth() - SpriteWidth(0)) / 2
MouseY = (ScreenHeight() - SpriteHeight(0)) / 2
MouseLocate(MouseX, MouseY)
; Start with released input
ReleaseMouse(#True)
InputReleased = 1
Repeat
Repeat
; Always process all the events to flush the queue at every frame
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
; Do the normal application management here
Gadget = EventGadget()
Select Gadget
Case 1
InputReleased = 0
ReleaseMouse(#False)
SetGadgetText(4, "Press 'F1' to ungrab keyboard and mouse")
EndSelect
EndSelect
Until Event = 0 ; Quit the event loop only when no more events are available
ExamineKeyboard()
If InputReleased = 0
If ExamineMouse()
MouseX = MouseX()
MouseY = MouseY()
EndIf
If KeyboardPushed(#PB_Key_F1)
ReleaseMouse(#True)
InputReleased = 1
SetGadgetText(4, "Mouse and keyboard released");
EndIf
EndIf
ClearScreen(RGB(0,0,0))
ClipSprite(0, #PB_Default , #PB_Default , #PB_Default , #PB_Default)
DisplaySprite(0, MouseX, MouseY)
FlipBuffers()
Until Quit Or KeyboardPushed(#PB_Key_Escape)
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
EndIf
EndIf