Window positions on multiple monitors

  1. 7 years ago

    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.

  2. Andrew L

    3 Aug 2013 San Francisco, CA, USA

    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).

  3. Axel S

    is not verified 3 Aug 2013 Europe (Germany, Erfurt)

    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)
  4. Axel S

    is not verified 3 Aug 2013 Europe (Germany, Erfurt)
    Edited 7 years ago

    Link was wrong

    RealEasyPrefs

  5. Karen A

    3 Aug 2013 Pre-Release Testers

    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!

  6. 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)?

  7. Dave S

    3 Aug 2013 San Diego, California USA

    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

  8. Sam R

    3 Aug 2013 Pre-Release Testers, Xojo Pro, Third Party Store Hengchun, Pingtung, Taiwan

    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.

  9. 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?

  10. Oliver O

    4 Aug 2013 Pre-Release Testers, Xojo Pro https://udemy.seminar.pro

    @TerrenceFindlay 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?

    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.

  11. Excellent, thanks for the help everyone!

  12. Sam R

    4 Aug 2013 Pre-Release Testers, Xojo Pro, Third Party Store Hengchun, Pingtung, Taiwan

    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.

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

  14. Sam R

    4 Aug 2013 Pre-Release Testers, Xojo Pro, Third Party Store Hengchun, Pingtung, Taiwan

    Thanks - Nice penguin ;)

or Sign Up to reply!