Page 1 of 1
Window save and restore?
Posted: Tue Jul 06, 2004 5:31 am
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
Posted: Tue Jul 06, 2004 6:36 am
by Shopro
Shouldn't using the Preference commands to write in the size of the window when the program is closed be sufficient?
-Shopro
Posted: Tue Jul 06, 2004 7:36 pm
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
