Page 1 of 1

[Win] WindowedScreen maximized and back

Posted: Sat Feb 20, 2010 12:45 am
by Kaeru Gaman
I messed around with the API a bit, to find out how to switch the frame and caption of a window on and off,
in order to be able to maximize a WindowedScreen fullscreen like, but have the caption on the window to be able to move it.

it works via SetWindowLongPtr and setting the styleflags
#WS_CLIPSIBLINGS | #WS_VISIBLE | #WS_CAPTION | #WS_SYSMENU for standard window and
#WS_CLIPSIBLINGS | #WS_VISIBLE | #WS_POPUP for the borderless window.

here is the code for the screen:

Code: Select all

#Window = 0

EnableExplicit

Global Dim Border.i(1)

Dim Schlange.POINT (31)

Dim StatusText.s(2)
StatusText(0) = "Window"
StatusText(1) = "Maximized"

Global.l Win_Width, Win_Height
Global.l Win_X, Win_Y
Global.l Desk_Width, Desk_Height

Global.d Fact_X, Fact_Y

Define.l Scrn_Width, Scrn_Height
Define.l WMX, WMY, MX, MY
Define.l BorderFlag = 0
Define.l EXIT, Event
Define.l Counter, n, t

ExamineDesktops()
  Desk_Width  = DesktopWidth(0)
  Desk_Height = DesktopHeight(0)

InitSprite()
InitKeyboard()

Procedure ChangeSize( Flag.l )
  Select Flag
    Case 0 
      SetWindowLongPtr_(WindowID(#Window), #GWL_STYLE, Border(Flag))
      SetWindowState( #Window, #PB_Window_Normal )
      ResizeWindow( #Window, Win_X, Win_Y, Win_Width, Win_Height )
    Case 1
      Win_X = WindowX(#Window)
      Win_Y = WindowY(#Window)
      SetWindowLongPtr_(WindowID(#Window), #GWL_STYLE, Border(Flag))
      SetWindowState( #Window, #PB_Window_Maximize )
      ExamineDesktops()
        Desk_Width  = DesktopWidth(0)
        Desk_Height = DesktopHeight(0)
  EndSelect
EndProcedure

Border(0) = #WS_CLIPSIBLINGS | #WS_VISIBLE | #WS_CAPTION | #WS_SYSMENU
Border(1) = #WS_CLIPSIBLINGS | #WS_VISIBLE | #WS_POPUP

Scrn_Width  = 1024
Scrn_Height =  768
Win_Width   = 1024
Win_Height  =  768

Fact_X = Desk_Width  / Scrn_Width
Fact_Y = Desk_Height / Scrn_Height

OpenWindow( #Window, 0,#PB_Ignore, Win_Width, Win_Height, "WindowedScreen Maximize Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
  Win_X = WindowX(#Window)
  Win_Y = WindowY(#Window)

OpenWindowedScreen( WindowID(#Window), 0,0, Scrn_Width,Scrn_Height, #True, 0, 0 )

For n=0 To 32
  Counter +1
  Schlange(0)\x = 512 + 256 * Sin( Counter / 20 )
  Schlange(0)\y = 384 + 192 * Cos( Counter / 15 )
  For t = 31 To 1 Step -1
    Schlange(t) = Schlange(t-1)
  Next
Next

Repeat
  Repeat
    Event = WindowEvent()
    If Event = #PB_Event_CloseWindow
      EXIT = 1
    EndIf
  Until Event = #Null

  WMX = WindowMouseX(0)
  WMY = WindowMouseY(0)
  If BorderFlag = 1
    MX = WMX / Fact_X
    MY = WMY / Fact_Y
  Else
    MX = WMX
    MY = WMY
  EndIf

  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_F11) And BorderFlag <> 0
    BorderFlag = 0
    ChangeSize( BorderFlag )
  EndIf
  If KeyboardPushed(#PB_Key_F12) And BorderFlag <> 1
    BorderFlag = 1
    ChangeSize( BorderFlag )
  EndIf
  If KeyboardPushed( #PB_Key_Escape )
    EXIT = 1
  EndIf

  Counter +1
  If Counter > 100000 * #PI
    Counter = 0
  EndIf

  ClearScreen( $201008 )
  StartDrawing(ScreenOutput())

    Schlange(0)\x = 512 + 256 * Sin( Counter / 20 )
    Schlange(0)\y = 384 + 192 * Cos( Counter / 15 )
    For t = 31 To 1 Step -1
      Schlange(t) = Schlange(t-1)
      Circle( Schlange(t)\x, Schlange(t)\y, 2*t, RGB( 0, 255 - 8*t, 255 - 8*t ) )
    Next

    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText( 1,  1, "[F11] Window    [F12] Maximize    [ESC] End", $0FF0FF )
    DrawText( 1, 25, "Status: " + StatusText( BorderFlag ), $0FF0FF )
    DrawText( 1, 49, "Position: " + Str(MX) + ", " + Str(MY), $0FF0FF )
  StopDrawing()
  FlipBuffers()
Until EXIT

Re: [Win] WindowedScreen maximized and back

Posted: Thu Feb 25, 2010 12:08 pm
by +18
very nice work, thanks Kaeru Gaman :D

Re: [Win] WindowedScreen maximized and back

Posted: Thu Feb 25, 2010 12:40 pm
by djes
:) Thank you!

Re: [Win] WindowedScreen maximized and back

Posted: Thu Feb 25, 2010 12:46 pm
by KJ67
Thank you, this is very useful.

Re: [Win] WindowedScreen maximized and back

Posted: Wed Jun 30, 2010 4:07 pm
by luis
Nice, thank you. :)