Tipswip   >   Windows   >   Windowsizelocation   >   Window Size And Location
For a better user interface, it is a good idea to store the last used (closed) size and location of each window instance for each user. Then when the user reopens a window instance, you can size and position it to the exact same size and position which they last closed the window.
A simple approach is to update the window's class size and location with the current instance size and location when the window is closed. It is best to put the code for this in the $destruct. This approach has a number or shortfalls. See "Simple Destruct Method" for more details.
A better approach is to store each window instance size and location by user in the data file.
In order to do this, you need to have some type of a 'logon' (Sign-In) method which the user must go through when entering your application. This way your application knows 'who' the user is.
I have a table in my data file called 'usr' which stores the usr_, name, password, direct phone number, email address, security access levels, etc. AND of course the 'usr_WindowsUsedList'
After the user successfully signs in, the 'usr_WindowsUsedList' is loaded into a class variable of the object class 'oWindowSizes'. A class variable is used for the windows used list in oWindowSizes so that the list will persist as the object class instances are opened and closed.
In the $construct of each window (in the base windows superclass) I have a line of code: Do oWindowSizes.$setWindowSize($cinst)
The method checks the WindowsUsed list, if the $cinst.()$name has been opened/closed by the user, then $setWindowSize, sets the size and position to the last used size and position.
In the $destruct of each window (in the base windows superclass) I have a line of code: Do oWindowSizes.$SaveWindowSize($cinst)
The method checks the WindowsUsed list, if the $cinst.()$name has been opened/closed by the user, then $setWindowSize, updates the size and position (and date/time), otherwise it adds it to the list.
Storing the windows opened by each user also gives you a security audit. You can check the user profiles to see all the windows each user has opened, and the date/time they last opened it.
The "oWindowSizes" object class which I use in my application has been copied into this StudioTips library, but since we aren't storing user profiles here, "oWindowSizes" have not been implemented in StudioTips. Feel free to copy "oWindowSizes" to your library and modify it to suit your needs. The methods for "oWindowSizes" are listed in this section with extra comments. "oWindowSizes" has been tested on Mac and Wintel platforms.The simple destruct method approach updates the window's class with the size and location of the current window instance size and location when the window is closed. It is best to put the code for this in the $destruct.
There are a number of shortfalls with the "Simple Destruct Method":
1. New version of software will wipe out the last closed window size and location.
2. It won't help users who use different workstations.
3. It can't save different instances of the same window class.
4. Overriding the inherited size and locations in subclass windows is extra work. (Special notation)
For a simple application with few windows and few updates the simple destruct method is fine. For an application that doesn't have a user sign-in method the simple destruct method is fine. I am using the simple destruct method in StudioTips.
See the sample code for the simple destruct code.
COPY CLASS DATA METHOD
Another possibility is to copy the $cinst properties to the $class. This will save ALL the properties of ALL the objects, methods, etc. of the current instance to its class. (This might be overkill?) You could put the following line in your window's $destruct method.
Do $cclass.$classdata.$assign($cinst.$classdata)