I am using Windows, and I have two monitors.
Some applications will always start on my primary monitor, no matter where they were when I closed them.
Ot
Correctly written Windows apps that want to save their location from run to run will save the results of GetWindowPlacement() before shutting down, then use SetWindowPlacement()
on startup to restore their position.
Frequently, apps will store the results of GetWindowPlacement()
in the registry as a REG_BINARY
for easy use.
The WINDOWPLACEMENT
route has many advantages over other methods:
SetWindowPlacement()
will automatically ensure that the window is not entirely offscreenFinally, programs that handle window restoration properly will take into account the nCmdShow
parameter passed in from the shell. This parameter is set in the shortcut that launches the application (Normal, Minimized, Maximize):
if(nCmdShow != SW_SHOWNORMAL)
placement.showCmd = nCmdShow; //allow shortcut to override
For non-Win32 applications, it's important to be sure that the method you're using to save/restore window position eventually uses the same underlying call, otherwise (like Java Swing's setBounds()
/getBounds()
problem) you'll end up writing a lot of extra code to re-implement functionality that's already there in the WINDOWPLACEMENT
functions.