- Code: Select all Expand view RUN
GetWindowPlacement( hWnd ) --> cState // Binary string of 44 bytes length
SetWindowPlacement( hWnd, cState)
Both these functions are wrappers to Windows API functions of the same names. More information about these functions can be found at:
https://docs.microsoft.com/en-us/window ... wplacement
https://docs.microsoft.com/en-us/window ... wplacement
Using these functions, two new methods are added to TWindow class.
- Code: Select all Expand view RUN
oWnd:SaveState() // --> cState (text of 88 bytes length)
oWnd:RestoreState( cState )
These methods apply to Windows and Dialogs, but not controls and child windows, including mdichild windows.
Example of typical usage:
- Code: Select all Expand view RUN
ACTIVATE WINDOW oWnd ;
ON INIT oWnd:RestoreState( MEMOREAD( "wndstate.txt" ) ) ;
VALID ( MEMOWRIT( "wndstate.txt", oWnd:SaveState() ), .t. )
Most of us have already been saving and restoring coordinates (top,left,width,height or top,left,bottom,right) of window when this functionality is required. But this practice fails in cases of different sizes of monitors and changing the number of multiple monitors. The new RestoreState() method is much safer in such cases too.
For example, let us consider two monitors of sizes 1920x1080 and 1366x768.
1. MAXIMIZED WINDOWS:
(a) Saving and restoring maximized window on monitor of same resolution:
Old method: The window is restored with maximized coordinates as normal dimensions and the real normal dimensions are forgotten. Clicking on the maximize/restore button does not restore the window to the original normal size.
RestoreState():Restores the window as maximized, but still remembers the original normal size coordinates. Clicking on maximize/restore button precisely restores to the correct normal size and position as earlier.
(b) Saving and restoring on monitors of different resolutions:
Old method: Window maximized on smaller screen is restored as a smaller window on large screen. Windows maximized on a larger screen, when restored on smaller screen, goes out of bounds.
RestoreState(): Irrespective of the sizes of the monitors, maximized when restored is maximized to fit the size of the new monitor. When maximize/restore button is clicked the window is displayed at the original normal size.
2. MULTIPLE MONITORS:
Old method:Window on secondary screen, when restored with only one monitor goes fully out of bounds and is not visible to the user.
RestoreState(): Window is restored on the primary monitor if the second monitor is not present.
In any case, the function ensures visibility of the window in the current setup.
If an existing application is saving and restoring windows/dialogs on the basis of coordinates, it is desirable to change using these new methods.