Window save and restore?

Everything else that doesn't fall into one of the other PB categories.
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Window save and restore?

Post by Dreglor »

i want to have my program be able to save it window state(minimize/maximize),width,height,x,y to a file when quitting and then on start up read the same file and resort it all

thanks in advance
~Dreglor
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post by Shopro »

Shouldn't using the Preference commands to write in the size of the window when the program is closed be sufficient?

-Shopro
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

this is the procs i use in my progs:

Code: Select all

Procedure.b Config_Load(WindowID.l)
  
  If OpenPreferences("config.ini")
    
    pos.WINDOWPLACEMENT
    
    pos\Length                  = SizeOf(WINDOWPLACEMENT)
    pos\ptMinPosition\x         = ReadPreferenceLong("MinPosX",-1)
    pos\ptMinPosition\y         = ReadPreferenceLong("MinPoxY",-1)
    pos\ptMaxPosition\x         = ReadPreferenceLong("MaxPosX",-1)
    pos\ptMaxPosition\y         = ReadPreferenceLong("MaxPosY",-1)
    pos\rcNormalPosition\Left   = ReadPreferenceLong("PosX1",0)
    pos\rcNormalPosition\Top    = ReadPreferenceLong("PosY1",0)
    pos\rcNormalPosition\Right  = ReadPreferenceLong("PosX2",100)
    pos\rcNormalPosition\Bottom = ReadPreferenceLong("PosY2",50)
    pos\showCmd                 = ReadPreferenceLong("Flags",1)
    
    SetWindowPlacement_(WindowID(WindowID),@pos)
    
    ProcedureReturn #True
    
  EndIf
  
EndProcedure

Procedure.b Config_Save(WindowID.l)
  
  If CreatePreferences("config.ini")
    
    pos.WINDOWPLACEMENT
    pos\Length = SizeOf(WINDOWPLACEMENT)
    
    GetWindowPlacement_(WindowID(WindowID),@pos)
    
    WritePreferenceLong("MinPosX",pos\ptMinPosition\x)
    WritePreferenceLong("MinPoxY",pos\ptMinPosition\y)
    WritePreferenceLong("MaxPosX",pos\ptMaxPosition\x)
    WritePreferenceLong("MaxPosY",pos\ptMaxPosition\y)
    WritePreferenceLong("PosX1",pos\rcNormalPosition\Left)
    WritePreferenceLong("PosY1",pos\rcNormalPosition\Top)
    WritePreferenceLong("PosX2",pos\rcNormalPosition\Right)
    WritePreferenceLong("PosY2",pos\rcNormalPosition\Bottom)
    WritePreferenceLong("Flags",pos\showCmd)
    
    ProcedureReturn #True
    
  EndIf
  
EndProcedure

If OpenWindow(0,100,100,100,100,#PB_Window_SizeGadget|#PB_Window_SystemMenu,"WindowPlacement")
  
  Config_Load(0)
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  
  Config_Save(0)
  
EndIf
Works fine ;-)
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply