Page 1 of 1

[Source] Restore Windows for OpenScreen() [Windows OS]

Posted: Fri Dec 15, 2023 10:01 pm
by Mijikai
So every window that is open when OpenScreen() is called can be misplaced (ex. multi monitor system) after the progam ends. :twisted:
This is highly annoying, so i wrote some code to reset all windows. :D

Code & Example (should also work on x86):

Code: Select all


EnableExplicit

Procedure.i RestoreWindows(Handle.i,Store.i)
  Static NewList *wp.WINDOWPLACEMENT()
  Select Store
    Case #True
      ForEach *wp()
        FreeMemory(*wp())
      Next
      ClearList(*wp())
      EnumWindows_(@RestoreWindows(),-1)
      ProcedureReturn #Null
    Case #False
      ForEach *wp()
        Store = PeekI(*wp() + SizeOf(WINDOWPLACEMENT))
        SetWindowPlacement_(Store,*wp())
        If *wp()\showCmd = #SW_MAXIMIZE;<- quick hack to deal with maximized windows ^_^
          ShowWindow_(Store,#SW_RESTORE)
          ShowWindow_(Store,*wp()\showCmd)
        EndIf
        FreeMemory(*wp())
      Next
      ClearList(*wp())
      ProcedureReturn #Null
    Default
      If IsWindowVisible_(Handle)
        Store = AllocateMemory(SizeOf(WINDOWPLACEMENT) + SizeOf(Integer))
        If Store
          If AddElement(*wp())
            *wp() = Store
            *wp()\Length = SizeOf(WINDOWPLACEMENT)
            GetWindowPlacement_(Handle,*wp())
            PokeI(*wp() + SizeOf(WINDOWPLACEMENT),Handle)
          Else
            FreeMemory(Store)
          EndIf
        EndIf
      EndIf
      ProcedureReturn #True
  EndSelect
EndProcedure

RestoreWindows(#Null,#True);<- store all window positions

InitSprite()
If OpenScreen(800,600,32,#Null$,#PB_Screen_WaitSynchronization,60)
  Repeat
    FlipBuffers()
  Until GetAsyncKeyState_(#VK_ESCAPE) & 1
  CloseScreen()
EndIf

RestoreWindows(#Null,#False);<- restore all window positions

End

Re: [Source] Restore Windows for OpenScreen() [Windows OS]

Posted: Sat Dec 16, 2023 5:00 am
by idle
good tip thanks

Re: [Source] Restore Windows for OpenScreen() [Windows OS]

Posted: Sun Apr 07, 2024 1:27 pm
by Jeromyal
This is great,

The compiler flag for DPI awareness can not be on or strange things happen.
But who needs a full screen app to be dpi aware anyway? (rhetorical)
however if there was a way to switch it off in code one could have a startup dialog dpi aware beforehand? (This ONE does not know)

I was initially excited seeing the title of this, thinking someone had solved the old mystery of how to switch from full screen to windowed screen and vise versa while using the 3d engine.
However, This is equally as good of a prize.