Requires: GfaWinx.lg32
Saves and loads the form's position on the screen to and from the registry. Especially useful with multiple-monitor systems.
SaveFormPos Form [, hKey$][, SubKey$] [, ValueName$]
fSuccess = LoadFormPos(Form [, hKey$][, SubKey$] [, ValueName$])
fSuccess | : Bool |
Form | : Form expression |
The SaveFormPos and LoadFormPos save and load the window's position properly on multi display systems. The position is not saved if the form is maximized or minimized.
SaveFormPos saves the Form's position in the registry under hKey$\SubKey$\ValueName$. The SaveFormPos syntax mimics the GB command SaveSetting, which is used by SaveFormPos to save the form's position. If hkey$ omits the registry's key (\\H*) the setting is saved in \\HKCU\Software. The default registry-entry for SaveFormPos and LoadFormPos is assembled from App.UserName and App.Name, the name for the value is Form.Name + "Placement", like this
\\HKCU\Software\UserName\AppName\FormName+Placement
Instead of the username you could simply use the companyname as follows:
SaveFormPos frm, App.CompanyName
The LoadFormPos function sets the global boolean variable LoadingFormPos to indicate execution.
'
' Samples\SaveFormPos.g32
'
$Library "gfawinx"
' Create a hidden window to prevent flash
OpenW Hidden 1, 0, 0, 300, 300, ~15
' Load window's last position.
LoadFormPos(Win_1)
' Show hidden form
Win_1.Show
Do
Sleep
Until Me Is Nothing
Sub Win_1_Destroy
SaveFormPos Win_1 ' \\HKCU\Software\UserName\AppName\Win_1Placement
EndSub
Sub Win_1_Paint
Text 12, 12, "LoadFormPos/SaveFormPos sample"
Text 12, 28, "Move form to different location and quit."
EndSub
The SaveFormPos and LoadFormPos use the GetWindowPlacement and SetWindowPlacement API's respectively.
ScaleToDpi, SaveSetting, GetSetting, App, WM_DPICHANGED
{Created by Sjouke Hamstra; Last updated: 23/02/2022 by James Gaite}