WinPos is handy tool for Microsoft Windows that can save and restore windows size, position and states through Windows API calls. The data is stored as JSON in %LOCALAPPDATA%\WinPos\WinPos.json file.
This is probably already present with installation of Microsoft Windows. If you are unsure you can use the following in a command line to determine the installed versions:
wmic product get description | findstr /C:".NET Framework"
WinPos [save] [restore]
Option | Description |
---|---|
save | Save current window positions |
restore | Restore previously saved window positions |
Save the current window positions into JSON file.
WinPos.exe save
Restore the window positions from JSON file.
WinPos.exe restore
- Interate through EnumWindows to get all current window handles.
- Call to GetWindowPlacement to get window details.
- If window is in normal state the position are determined by GetWindowRect. This allows to get the details of windows that are positioned by Windows Snap.
- Write JSON file with the following details:
- Handle
- Title
- WindowPlacement
- Length
- Flags
- ShowCmd
- PtMinPosition
- PtMaxPosition
- RcNormalPosition
- Read window data from JSON file according chapter save.
- Iterate through data.
- Call SetWindowPlacement using handle with the WindowPlacement details.
Remark: If the window handle has changed somehow the window cannot be found and is not repositioned.
- NuGet Package Json.NET for serialize and deserialize JSON
WinPos is open source under the MIT License and is free for commercial use.