Window positions on multiple monitors

Is there any way to save and restore window positions across several monitors ?
I have looked at the Screen function but can’t figure out how to save and retrieve window locations with it. Simple code would be greatly appreciated.

You can use the Window.Top and Window.Left properties to save/restore a window’s position. Left and Top are respectively the X and Y coordinates of the top-left corner of the window relative to the top-left corner of Screen(0).

I use RealEasyPrefs

http://code.google.com/p/realeasyprefs/downloads/list]RealEasyPrefs

save

SetPrefNumber("Left", Window1.Left) SetPrefNumber("Top", Window1.Top) SetPrefNumber("Width", Window1.Width) SetPrefNumber("Height", Window1.Height) SetPrefNumber("Left2", Window2.Left) SetPrefNumber("Top2", Window2.Top) SetPrefNumber("Width2", Window2.Width) SetPrefNumber("Height2", Window2.Height)
load

Window1.Left=GetPrefNumber("Left", Window1.Left) Window1.Top=GetPrefNumber("Top", Window1.Top) Window1.Width=GetPrefNumber("Width", Window1.Width) Window1.Height=GetPrefNumber("Height", Window1.Height) Window2.Left=GetPrefNumber("Left2", Window2.Left) Window2.Top=GetPrefNumber("Top2", Window2.Top) Window2.Width=GetPrefNumber("Width2", Window2.Width) Window2.Height=GetPrefNumber("Height2", Window2.Height)

Link was wrong

RealEasyPrefs

When you save the window positions, you also might want to save the monitor configurations/resolutions, and check that when restoring. If it different you might want to make sure you do something sensible.

I hated apps that messed up window positions if you changed monitor resolutions or configurations between app runs!

I know how to save and restore window positions on a single monitor. What I’m trying to figure out is how to save and restore window positions on two or more monitors so that my apps windows will open in the correct position on the correct screen. For example, say Window1 is on screen(0) and Window2 is on screen(1). How do I make sure that Window one opens on screen(0) and Window2 opens on screen(1)?

The exact same way.

If monitor one is 1280 x 768 and so is monitor #2… the coordinates for monitor #1 is 0 to 1279, and monitor #2 is 1280 to 2559

The coordinate system treats the monitors as one big map in that regard

For Cocoa, there is a declare where you can get the OS to save and restore window positions in the preferences, I wouldn’t advise it for document window, but for palettes it’s fine. Oh, yeah there is also a Cocoa function for getting & setting the window frame via string. If you think these’ll help I’ll dig out the declares when I’m back at my computer.

Dave, so in your example, a window1.left on monitor # 1 would be between 0 and 1279 and window2.left would be between 1280 and 2559.

If I undstand this correctly I don’t have to do anything other than save and restore the window positions as per usual. Then when I retrieve these values and set window positions to them the windows will naturally appear on the same monitor they were on when i saved thier positions. Is this correct?

[quote=25018:@Terrence Findlay]Dave, so in your example, a window1.left on monitor # 1 would be between 0 and 1279 and window2.left would be between 1280 and 2559.

If I undstand this correctly I don’t have to do anything other than save and restore the window positions as per usual. Then when I retrieve these values and set window positions to them the windows will naturally appear on the same monitor they were on when i saved thier positions. Is this correct?[/quote]
Yes., exactly.

However, you have to provide some kind of “show-on-main-screen” option, in case the secondary monitor is no longer there once you restore the saved position.

Excellent, thanks for the help everyone!

Indeed, you do need to find a way to either allow the user to force all windows on the main screen or automatically check to make sure that it’s being displayed in the visible area.

Thanks Sam. I believe I have that covered. Nice dog!

Thanks - Nice penguin :wink: