Screen dies when Desktop changes...?
Posted: Sat Feb 20, 2010 2:13 pm
why does a WindowedScreen die when I change the Desktop's resolution?
the debugger reports "the specified output is NULL" when the resolution is changed and the StartDrawing is called again.
the debugger reports "the specified output is NULL" when the resolution is changed and the StartDrawing is called again.
Code: Select all
#Window = 0
EnableExplicit
Global Dim Border.i(1)
Dim Schlange.POINT (31)
Dim StatusText.s(2)
StatusText(0) = "Fenster"
StatusText(1) = "Vollbild"
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 Restore_Desktop()
ChangeDisplaySettings_(0, 0)
EndProcedure
Procedure.i Change_Desktop(Width.l, Height.l, Mode.l)
Protected dmScreenSettings.DEVMODE
Protected Check
dmScreenSettings\dmSize = SizeOf(dmScreenSettings)
dmScreenSettings\dmPelsWidth = Width
dmScreenSettings\dmPelsHeight = Height
dmScreenSettings\dmFields = #DM_PELSWIDTH | #DM_PELSHEIGHT
Check = ChangeDisplaySettings_(@dmScreenSettings, Mode)
ProcedureReturn Check
EndProcedure
Procedure ChangeSize( Flag.l )
Select Flag
Case 0
SetWindowLongPtr_(WindowID(#Window), #GWL_STYLE, Border(Flag))
Restore_Desktop()
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))
Change_Desktop(Win_Width, Win_Height, #CDS_FULLSCREEN )
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] Fenster [F12] Vollbild [ESC] Beenden", $0FF0FF )
DrawText( 1, 25, "Status: " + StatusText( BorderFlag ), $0FF0FF )
DrawText( 1, 49, "Position: " + Str(MX) + ", " + Str(MY), $0FF0FF )
StopDrawing()
FlipBuffers()
Until EXIT