Hi,
This is possibly a very question. I am writing the posions of my program to an ini file before it closes so that I can read them back in agian. I am tring to make sure the window reappears on the screen in the exact location that it shut down in. I am close but it would apear when I use GetWindowRect_ it returns only the window portion not the frame around it. Is there an API call that will give me the exact location of the whole window including the frame and caption.
Thanks
Saving window position so it starts in same place again.
-
- Enthusiast
- Posts: 202
- Joined: Sun Apr 27, 2003 4:44 am
- Location: Michigan, USA
- Contact:
Saving window position so it starts in same place again.
-Ryan
RJP Computing
Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
RJP Computing
Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
-
- Enthusiast
- Posts: 202
- Joined: Sun Apr 27, 2003 4:44 am
- Location: Michigan, USA
- Contact:
This is prob too late but I wrote 2 examples of ways of doing it, I guess it could be of use to some people
First using procedures
And secondly without using procedures which I have annotated
By the way how could I get 2 returns from a procedure and assign each one a different variable. If it's not pos then no probs
First using procedures
Code: Select all
Procedure GetXpos()
appdir$=Space(255)
GetCurrentDirectory_(255,@appdir$)
If Right(appdir$,1)<>"\"
appdir$+"\"
EndIf
If FileSize(""+appdir$+"\Config.ini")=-1
Xpos = 100
EndIf
If FileSize(""+appdir$+"\Config.ini")<>-1
OpenPreferences("Config.ini")
Xpos = ReadPreferenceLong("Xaxis",0)
ClosePreferences()
EndIf
If Xpos < 0
Xpos = 100
EndIf
ProcedureReturn Xpos
EndProcedure
Procedure GetYpos()
appdir$=Space(255)
GetCurrentDirectory_(255,@appdir$)
If Right(appdir$,1)<>"\"
appdir$+"\"
EndIf
If FileSize(""+appdir$+"\Config.ini")=-1
Ypos = 100
EndIf
If FileSize(""+appdir$+"\Config.ini")<>-1
OpenPreferences("Config.ini")
Ypos = ReadPreferenceLong("Yaxis",0)
ClosePreferences()
EndIf
If Ypos < 0
Ypos = 100
EndIf
ProcedureReturn Ypos
EndProcedure
Procedure WriteConfig()
CreatePreferences("Config.ini")
WritePreferenceLong("Xaxis",WindowX())
WritePreferenceLong("Yaxis",WindowY())
ClosePreferences()
EndProcedure
appdir$=Space(255)
GetCurrentDirectory_(255,@appdir$)
Ypos = GetYpos()
Xpos = GetXpos()
OpenWindow(#1,Xpos,Ypos,195,200,#PB_Window_MinimizeGadget,"TEST - By Joey")
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
Writeconfig()
Code: Select all
appdir$=Space(255)
GetCurrentDirectory_(255,@appdir$) ;Getting directory run from
If Right(appdir$,1)<>"\"
appdir$+"\"
EndIf
If FileSize(""+appdir$+"\Config.ini")=-1
Xpos = 100 ;Checking if a config file already exists
Ypos = 100 ;If it does not it is setting default co-ordinates
EndIf
If FileSize(""+appdir$+"\Config.ini")<>-1 ;If config file does exist reading longs to give co-ordinates
OpenPreferences("Config.ini") ;for window to be created at
Xpos = ReadPreferenceLong("Xaxis",xaxis)
Ypos = ReadPreferenceLong("Yaxis",yaxis)
If Xpos < 0 ;This bit is to combat the fact that if app is closed when minimized it will
Xpos = 100 ;give negative co-ordinates, these 2 parts make sure it appears all be it in
EndIf ;the default location
If Ypos < 0
Ypos = 100
EndIf
EndIf
OpenWindow(#1,Xpos,Ypos,195,180,#PB_Window_MinimizeGadget,"TEST - By Joey")
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
xaxis =WindowX() ;This bit records where the window was closed
yaxis =WindowY()
CreatePreferences("Config.ini")
WritePreferenceLong("Xaxis",xaxis)
WritePreferenceLong("Yaxis",yaxis)
ClosePreferences()
ReadPreference commands allow you to set a default value if one is not found so you do not have to do all the file checking. Also, only CreatePreferences needs a check.
Here is a more simple form of your code...
Here is a more simple form of your code...
Code: Select all
OpenPreferences("Config.ini")
Xpos=ReadPreferenceLong("Xaxis",100)
Ypos=ReadPreferenceLong("Yaxis",100)
ClosePreferences()
If Xpos<0:Xpos=100:EndIf
If Ypos<0:Ypos=100:EndIf
If OpenWindow(1,Xpos,Ypos,195,180,#PB_Window_MinimizeGadget,"TEST")
Repeat
EventID=WaitWindowEvent()
Until EventID=#PB_Event_CloseWindow
If CreatePreferences("Config.ini")
WritePreferenceLong("Xaxis",WindowX())
WritePreferenceLong("Yaxis",WindowY())
ClosePreferences()
EndIf
EndIf
Last edited by Paul on Tue Mar 23, 2004 11:00 pm, edited 1 time in total.