I'm sure i've posted this code in here before but here goes again
Here is how I'm handling it so far . This is still a work in progress ..
Let me know what you think. any hints,tips,corrections,advice, helpfull critisisms are more than welcome
Handles loosing focus, Alt Tab , alt enter , minimising window or full screen and re-opening via task bar, in all modes that i can think of.. window , fullscreen , fake fullscreen borderless window etc...
Graphic screen is same resolution no matter if in fullscreen or window
Note: Transparent mode works on Xp and Win7 but only in basic not aero mode

still working out how to get that to work
Code: Select all
;{ Set up Variables
Global AltTab = 0
Global ScrMode = 1
Global WinState = 0
Global WinH = 0
Global WinId = 0
Global Quit = 0
Global WinX = 0
Global WinY = 0
Global WinWidth = 800
Global WinHeight = 600
Global Transparent = RGBA(255,0,255,0)
Global Background = Transparent; #Black ; #Blue RGB(r,g,b) RGBA(r,g,b,a)
Global WinFlags = #PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget
Global Title.s = "test"
Global ScrMode = 0
Global ScrX = 0
Global ScrY = 0
Global ScrWidth = 640
Global ScrHeight = 480
Global ScrDepth = 32
;}
Procedure SwitchScreen()
ScrMode = ScrMode ! 1
If WinState
CloseScreen()
Else
WinState=1
EndIf
If ScrMode = 0 ; Windowed
WinH = OpenWindow(WinId, WinX, WinY, WinWidth, WinHeight, Title.s, WinFlags)
If AltTab
SetWindowState(WinId,#PB_Window_Minimize)
Else
SetWindowLong_(WinH,#GWL_EXSTYLE,GetWindowLong_(WinH,#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_COMPOSITED)
If Background=Transparent
SetWindowLong_(WinH,#GWL_EXSTYLE,GetWindowLong_(WinH,#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_COMPOSITED)
SetLayeredWindowAttributes_(WinH, Transparent, 0, #LWA_COLORKEY)
EndIf
EndIf
OpenWindowedScreen(WinH, ScrX,ScrY, ScrWidth, ScrHeight, 1, 0, 0)
SetFocus_(WinH)
Else
If WinH : CloseWindow(WinId) : WinHeight : EndIf
If Background=Transparent
WinH = OpenWindow(WinId, 0, 0, DesktopWidth(0),DesktopHeight(0), Title.s, #PB_Window_BorderLess)
SetWindowLong_(WinH,#GWL_EXSTYLE,GetWindowLong_(WinH,#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_COMPOSITED)
SetLayeredWindowAttributes_(WinH, Transparent, 0, #LWA_COLORKEY)
OpenWindowedScreen(WinH, ScrX,ScrY, ScrWidth, ScrHeight, 1, 0, 0)
Else
OpenScreen(ScrWidth, ScrHeight, ScrDepth, Title.s)
EndIf
EndIf
EndProcedure
Procedure RenderScreen()
ClearScreen(Background)
StartDrawing(ScreenOutput())
DrawingMode(4)
Box(0, 0, ScrWidth, ScrHeight , #Red)
LineXY(0, 0, ScrWidth, ScrHeight , #Red)
LineXY(0, ScrHeight, ScrWidth, 0 , #Red)
Circle((ScrWidth-1)/2, (ScrHeight-1)/2, (ScrHeight-1)/2, #Red)
DrawingMode(1)
FrontColor (RGB(255,128,0))
If ScrMode=0
DrawText(10,14,"Screen Size : "+Str(ScrWidth)+","+Str(ScrHeight))
DrawText(10,28,"Window Size : "+Str(WinWidth)+","+Str(WinHeight))
Else
DrawText(10,10,"Screen Size : "+Str(ScrWidth)+","+Str(ScrHeight))
If Background=Transparent
WinWidth = WindowWidth(WinId)
WinHeight = WindowHeight(WinId)
DrawText(10,28,"Full Screen/Window Size : "+Str(WinWidth)+","+Str(WinHeight))
EndIf
EndIf
DrawText(10,42,"Press T to Toggle Transparent mode")
StopDrawing()
FlipBuffers()
EndProcedure
Procedure HandleEvents()
ExamineKeyboard()
; Toggle_Screen_Mode
If ((KeyboardPushed(#PB_Key_LeftAlt) Or 0) Or (KeyboardPushed(#PB_Key_RightAlt) Or 0)) And ((KeyboardPushed(#PB_Key_Return) Or 0) Or (KeyboardPushed(#PB_Key_PadEnter) Or 0))
SwitchScreen()
EndIf
If ((KeyboardReleased(#PB_Key_T) Or 0))
If Background=Transparent
Background=#Black
Else
Background=Transparent
EndIf
ScrMode = ScrMode ! 1
SwitchScreen()
EndIf
If KeyboardPushed(#PB_Key_Escape)
Quit=1
EndIf
; Handle if fullscreen looses focus eg: alt-Tab
If IsScreenActive() <> 1
If ScrMode=1 And Background <> Transparent
AltTab=1
SwitchScreen()
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
Quit=1
Default
;do nothing
EndSelect
Delay(1)
Until IsScreenActive() <>0 Or Quit =1
SwitchScreen()
AltTab=0
EndIf
EndIf
; If ScrMode=0 Or Background=Transparent
Select WindowEvent()
Case #WM_SIZE
WinWidth = WindowWidth(WinId)
WinHeight = WindowHeight(WinId)
Case #PB_Event_CloseWindow
Quit=1
Default
; do nothing .. just here to clear the queue
EndSelect
; EndIf
EndProcedure
Procedure Initialize()
If InitSprite()=0 Or InitKeyboard()=0 Or InitMouse()=0 Or ExamineDesktops()=0
MessageRequester("ERROR","Can't initialize!",#MB_ICONERROR):End
EndIf
; sneaky way of opening window or screen
SwitchScreen()
EndProcedure
Procedure QuitProgram()
CloseScreen()
CloseWindow(WinId)
EndProcedure
;{ Main Program
Initialize()
Repeat
RenderScreen()
HandleEvents()
Delay(1)
Until Quit=1
QuitProgram()
;}