Why does the primary monitor have (0,0) as its upper left coordinate?


By definition, the primary monitor is the monitor that has (0,0) as its upper left corner. Why can't the primary monitor be positioned somewhere else?

Well, sure you could do that, but then you'd have to invent a new name for the monitor whose upper left corner is at (0,0), and then you're back where you started.

In other words, it's just a name. You could ask, "Why can't starboard be on the left-hand side of the boat?" Well, sure you could do that, but then you'd have to come up with a new name for the right-hand side of the boat, and then things are pretty much the same as they were, just with different names.

Perhaps a more descriptive (but clumsier) name for the primary monitor would be the backward-compatibility monitor (for applications which do not support multiple monitors), because that's what the primary monitor is. If an application is not multiple-monitor aware, then any time it asks for properties of "the" monitor, it gets information about the backward-compatibility monitor. A call to GetSystemMetrics(SM_CXSCREEN) gives the width of the backward-compatibility monitor, GetSystemMetrics(SM_CYMAXIMIZED) gives the height of a window maximized on the backward-compatibility monitor, and positioning a window at (0,0) puts it at the upper left corner of the backward-compatibility monitor.

The window manager still respects window coordinates passed to functions like CreateWindow or SetWindowPos. If you pass coordinates that are on a secondary monitor—oops—a monitor different from the backward-compatibility monitor, then the window manager will happily put the window there. These coordinates might be the result of a program that is multiple-monitor aware, or possibly merely from a program which is multiple-monitor agnostic.

Multiple-monitor agnosticism is a term I just made up which refers to programs which might not explicitly support multiple monitors, but at least were open to the possibility of multiple monitors by not making assumptions about the number of monitors but instead using functions like RectVisible to determine what the visible portions of the screen are. These techniques were hot topics many years ago when you wanted to write a program that ran both on single-monitor-only versions of Windows as well as multiple-monitor versions of windows; nowadays there are rather old-fashioned, like coming up with mnemonics for all your friends' telephone numbers so you didn't have to keep looking them up. (Today, you just go ahead and call the multiple monitor functions and use the address book function in your mobile phone to remember your friends' phone numbers.)

It is not the case that the primary monitor is the applications show up here first monitor. As noted earlier, applications show up on whatever monitor they ask for, whether they asked for it explicitly (hunting around for a monitor and using it) or implicitly (restoring to the same coordinates they were on when they were last run).

Of course, programs which pass CW_USEDEFAULT to the CreateWindow function explicitly abdicated the choice of the window position and therefore the monitor. In that case, the window manager tries to guess an appropriate monitor. If the new window has a parent or owner, then it is placed on the same monitor as that parent or owner; otherwise, the window manager just puts the window on the backward-compatible monitor, for lack of a better idea.

Comments (31)
  1. Matt says:

    As a test, I just moved my taskbar from my primary (left) to secondary (right) monitor and everything was fine.

  2. frymaster says:

    i have a multi-monitor agnostic app (it's a port from linux) that remembers where it last was, and is designed to be a desktop widget type of thing so doesn't have a task bar entry (or notification area entry).  This is fine until I rearrange my monitors, at which point it'll STILL start up at the same coordinates it used to, off the side of the screen :(

  3. Damien says:

    @Ian – It's not Windows treating one monitor specially. It's rather than applications with no knowledge of multiple monitors are going to ask for their window to be positioned at (0,0) (or close thereto, based on their reading of other system metrics).

  4. DWalker says:

    Obviously, Starboard should be on the left-hand side of the boat.  And the coordinates (0,0) should be in the lower-left corner of the screen, like all good graphs.  :-)

  5. Bob says:

    Wow, thanks.  That explains lots of strange application behavior.  Now if only that application were to stop treating my workspace (with multiple monitors of different sizes) as if it were one gigantic rectangle and would keep everything visible.

  6. Joey says:

    Last time I used Windows on multiple monitors, probably a decade ago, Media Player wouldn't play my file on anything but the primary monitor, which meant I had to make my TV the primary monitor, which meant the taskbar would appear by default on the TV and be unreadable. I came to the assumption that Windows can only play video on the primary monitor, and I'm sure I wasn't alone. I think whoever originally asked the question in the title has a similar misconception; to answer what they need (and not what they asked) one would have to have a series of "why do you care about that" question, as is very often the case (as has been demonstrated quite a few times on this blog)

  7. James Schend says:

    BTW things get even more fun if your monitor-space isn't rectangular, but L-shaped. You still find some apps that do use the max-X and max-Y coordinate to estimate the screen space, then cut-off parts of their own UI. Sometimes making them impossible to close, although thankfully not often.

    Frymaster: A ton of programs have that problem, sadly. What's even worse is when you report the bug, and they don't believe you! (I had that experience with a Microsoft group that will go unnamed. Posting a screenshot seems to have convinced them, and they've promised the fix will be in the next version.)

    Until Raymond posted the "right-click, Move, Arrow-key, drag mouse" fix for getting these windows back on the screen, I used to have no recourse than re-installing a half-dozen apps just because I unplugged a monitor.

  8. Kdansky says:

    What about games? Most games cannot run on the secondary monitor and totally insist on using the primary, even if they can use both. You get either primary or primary + secondary, but never just the secondary. Is there a special treatment for DirectX/OpenGL or is that just lazyness on the dev's parts?

    And as a sidenote: Windows XP creates the start menu height out of the height of the primary monitor, no matter on which one that task bar is actually on and that can result in a startmenu that is actually bigger than the screen. And then it does not use two columns (as it would if it was on the primary), but instead starts to scroll.

    So if I get this right: Windows XP is not compatible with multiple monitors and must use the "backwards compatibility fix"? ;)

  9. Marquess says:

    @DWalker59

    Well, there's still OS/2 (and eComStation) if you want a sensible coordinate system ;)

  10. Mott555 says:

    I have three 19" screens for work, with the center one as my primary. I also like having wallpapers that span across all three screens, but they always start from the primary, so the far-right section of the image ends up being on the leftmost screen. My solution has been to open the image in Paint, grab the leftmost 1280 x 1024 pixels, and move them to the end. It looks really weird as an image but then everything works out once it's set as the background.

  11. Tim Dawson says:

    I think that if you don't specify a startup monitor, the window manager will put the window on whatever monitor the mouse happens to be on. It would be interesting to see the full algorithm for determining this.

  12. Random832 says:

    "otherwise, the window manager just puts the window on the backward-compatible monitor, for lack of a better idea."

    That's some impressive lead-burying, there… the _real_ question is, why isn't it possible to set the "monitor that the window manager puts windows on for lack of a better idea" (some people's actual mental model of the term "primary monitor") to be something other than the "backward-compatibility monitor" [for apps that make single-monitor assumptions] at (0,0)? Since, you know, stuff breaks when stuff is placed in negative coordinates, but you might want CW_USEDEFAULT apps to start on the right-hand screen.

    So, no, it's not just a name. It's two separate pieces of functionality (backwards compatibility for single-monitor apps vs CW_USEDEFAULT placement) that are tied together for no immediately apparent reason.

    @Damien – yes, windows does treat one monitor specially, but you might have missed where he admitted it since it was at the bottom of the post.

    [CW_USEDEFAULT goes on the compatibility monitor for compatibility reasons. Putting it on some other monitor wouldn't be backward-compatible. -Raymond]
  13. me says:

    Interestingly, WM_CONTEXTMENU uses position (-1,-1), which is valid in a mutiple monitor setup, to signal an unknown position:

    blogs.msdn.com/…/232369.aspx

  14. configurator says:

    @me, yes, but (if I'm not mistaken) these are control coordinates, not screen coordinates – controls shouldn't have these as valid coordinates no matter how many screens we've got.

  15. DWalker says:

    @marquess:  Ugh, no, I tried OS/2 once for a short while.  

  16. Jules says:

    Kdansky, James Schend: both DirectX and OpenGL support full screen apps on any monitor.  If one will only work on the primary monitor, that's simply because the developer hasn't bothered putting an option in to allow you to select a different one.

    The only thing you can't do (and I've never been able to figure out why not) is have a full screen app using multiple monitors.

    [If you had a single surface that spanned display cards, the memory for the surface would no longer be contiguous. How would you fill out the D3DLOCKED_RECT? -Raymond]
  17. Ian says:

    I suspect the real question was not to do with what we call the monitor whose upper left corner is at (0, 0), but more 'why does the monitor that Windows treats as special have to have (0, 0) as its upper left corner?'

    I have a dual monitor setup with the primary monitor on the right so that my Start menu is in the centre of my working area. As a result, the left-hand monitor has negative X coordinates and a lot of applications misbehave as a consequence. Usually it is trivial things like tooltips popping up on the wrong monitor.

    If (0, 0) was at the top-left of my left-hand monitor and I could *still* keep my task bar and start menu on the right-hand monitor, then this problem would not occur.

    I suppose the problem then would be a non-multi-monitor-aware application that assume that the width of its monitor is equal to the maximum X coordinate: if the two monitors are not the same height and colour depth then treating them as a single monitor might not go too well.

    I think Microsoft made a reasonable choice.

  18. James Schend says:

    Jules & Raymond: There's also the issue that the multiple-monitor space isn't necessarily rectangular. That would wreak havoc with most games, and require a decent amount of code from the game developer to compensate.

    I seem to recall some flight sims could run on 3 monitors if certain assumptions were met– this might pre-date DirectX, though, and they might have just been drawing the old-fashioned way on them.

    Frankly, I'd rate this issue relatively low priority for game developers. I'd much rather they start testing their games with USB microphones and sound cards– especially when hot-swapping them. It's still not uncommon for a game to free or crash simply because you plug-in a USB sound device. (WOW copes with it– but only by locking-up long enough that you almost assume it's crashed.)

    Media players (like Zune and iTunes) seem to have issues with this too– if you unplug a USB headset while the Zune software is running, it'll stop playback falsely claim your computer has no sound card. iTunes will continue playing, just with no sound. (Not even if you plug it back in.) I've reported this bug to both teams.

    It's not like USB is brand-new or something. Sorry to go off on a totally off-topic tangent…

  19. Joshua says:

    [If you had a single surface that spanned display cards, the memory for the surface would no longer be contiguous. How would you fill out the D3DLOCKED_RECT? -Raymond]

    All right that's so egregious I've got to comment on it.

    It can be done, but it would be heavy architecture changes to do it. The answer is to render the graphics to a memory buffer then blit the memory buffer to both screens. If you think this is crazy, this is like how Linux systems can use OpenGL when working remotely.

    [True, you could do that, but then it's not very "direct" any more. -Raymond]
  20. Random832 says:

    Avoiding valid negative coordinates is also a compatibility concern, and the compatibility impact of placing a program which explicitly doesn't care where it is placed on a monitor other than the (0,0) one is unclear.

  21. Steve says:

    @configurator: Nope, WM_CONTEXTMENU uses screen coordinates.

  22. James Schend says:

    Kdansky: Games can use any monitor they want. If they're restricting *themselves* to the main monitor, it's because they were programmed by incompetents. (Sadly, not very rare in that industry.)

    That said, when you put a game in "fullscreen" mode, it implies, "fullscreen on the main monitor". But in Windowed mode, you can drag the window whereever and it'll (should) work fine. I always run World of Warcraft on my secondary monitor, for example.

  23. Worf says:

    Games supporting multi-monitors are common now – especially with nVidia Fermi and ATi Eyefinity, which let you have massive setups (like 3-screen or 6-screen).

    But then again, these cards have multiple outputs so one surface could have contiguous memory, and the multi-card scenario often requires them to share memory.

    If you use two discrete cards then it's likely that you get single-screen gameplay.

    The only real drag is if the game itself doesn't support the oddball resolution…

  24. Leo Davidson says:

    @Joey: The OS itself can play videos on multiple monitors but some combinations of playback methods and drivers won't work.

    Some video playback modes use video hardware stuff which won't work on anything but the primary monitor, or won't work if a window spans monitors (where you get blank video in the half of the window on another monitor), or will work but very slowly.

    Other video playback modes work fine, presumably with some slight performance hit that isn't an issue on modern hardware.

    (If you want to play around with this, grab Media Player Classic (unrelated to Windows Media Player) which has an options page where you can choose from the many different playback methods and see how they work on your hardware/drivers.)

    That said, even now there's an annoyance in many programs where the can play video on any monitor, and even span monitors, but when their window is moved (fully) from one monitor to the other the playback glitches for a second or two. I guess they're re-initialising the playback with the other monitor in mind (perhaps in case the hardware/drivers/method requires it) but it isn't necessary and the glitch is annoying. (Occasionally, the glitch turns into a crash of the app, too, so I'm double-weary about moving some program's video windows between monitors.)

  25. Martin Brown says:

    Starboard is on the left of the boat, if your facing aft. That is why sailors use port and starboard and not left and right.

  26. Miral says:

    In my experience, CW_USEDEFAULT doesn't always put ownerless windows on the primary monitor.  Most of the time, the behaviour seems to be closer to "put the window on whatever monitor happens to contain the mouse pointer at the moment" (although sometimes it seems to follow whichever monitor the current foreground window is on rather than the mouse pointer, and sometimes it doesn't; hence my uncertainty).

  27. 640k says:

    The multimon wallpaper blog message exposes one obvious flaw of windows. There should be a better interface for the user to customize the multi image layout. The current "infinite tile"-mode is a bad hack which breaks regularly, for example when IE puts a new image as a new desktop wallpaper. There's also bugs in vista/windows 7 current customization gui which weren't there in xp. Please fix this in a correct way in windows 8 or remove the feature.

  28. Mike S. says:

    The original version of Doom had a 3 monitor mode, but it required 3 computers, one for each monitor.

  29. DWalker says:

    @640k:  This is not a forum to ask that bugs get fixed.  There is a place for that.

  30. configurator says:

    @Martin Brown: That would be your left, still the right of the boat.

    If the boat is facing aft, though, that's a different story altogether!

  31. John "Z-Bo" Zabroski says:

    @Raymond Chen

    @Multiple-monitor agnosticism is a term I just made up which refers to programs which might not explicitly support multiple monitors, but at least were open to the possibility of multiple monitors by not making assumptions about the number of monitors but instead using functions like RectVisible to determine what the visible portions of the screen are.

    Interesting.  So your advice is that applications should build a "world view" into their window layout policies subsystem, using RectVisible for "world view" and persistent window coordinates for "model view"?  This makes sense, but a much cheaper alternative guaranteed to at least display the whole screen is SetWindowPlacement and GetWindowPlacement.  If there is a bug in the custom "world view" to "model view" (WV2MV) mapper, then SetWindowPlacement will correct it.  Technically, a developer could layer the mapper by finally calling SetWindowPlacement, to catch any layout policy bugs.

    It is really annoying being called into the CEO's office when your flagship product has serialized coordinates on his home laptop and he brought in the laptop and hooked it up to a projector.  Multi-monitor agnosticism also includes the fact that sometimes monitors are not always connected, or the connection paths are not always the same!  Such policy-based layout design I describe is resilient to being called into the CEOs office when some modal dialog pops up on the screen w/ "model view" settings from his home multi-monitor set-up — he can't close it on the projector because the 'x' and top-left corner is off-screen and the chrome doesn't allow you to drag windows around.

Comments are closed.

Skip to main content