When I use Alt+PrtSc to take a screen shot of a maximized window, why does it capture a few pixels from an adjacent monitor?


On a dual-monitor system, maximize a window onto one monitor, and then use the Alt+PrtSc hotkey to capture a screen shot of that window. The resulting bitmap captures a few pixels from the adjacent monitor. Why is that?

This is a consequence of a phenomenon I discussed some time ago: Maximized windows actually extend beyond the edges of the monitor. This is done so that the main window body fills the monitor, and the borders hang off the edge. The theory is that you want to fill the screen with the useful parts of the window, and you're not interested in the borders.

The code that handles the Alt+PrtSc hotkey captures the entire window, including the parts that hang off the monitor. On three of the sides, there is no content on the other side of the monitor, so the attempt to capture those borders fails. But on the fourth side, the screen capture code sees that the pixels are still valid, and it includes them in the bitmap even though they're on the wrong monitor.

You might be tempted to fix this by clipping the screen shot to the current monitor, but that would result in partial screen shots in the case where the user has a window that intentionally straddles more than one monitor.

Comments (36)
  1. Antonio Rodríguez says:

    How about detecting if the window si maximized and, if so, clip to a rectangle that excludes its borders? This could be done only when multiple monitors are present. It wouldn’t be too much work even for a edge case. But maybe the testing would be more work than the code itself, and maybe someone is relying on this as a feature: https://xkcd.com/1172/

    1. The MAZZTer says:

      Won’t work for custom drawn windows. How do you know how much to clip? For example Visual Studio 2017 does not seem to hang off the edges when capturing its maximized window. If you clipped anything you’d be clipping actual visual content.

      1. Joshua says:

        You clip at the screen boundary.

      2. David-T says:

        As Raymond’s earlier post on the subject ends:

        > This decoupling of logical and physical characteristics permits all sorts of visual tricks. The visual trick relevant here is the removal of the overhang borders from a maximized window. The borders are still there: If you call GetWindowRect, you will get the same coordinates you always did. But they don’t appear on the screen. The sliver is gone.

        You detect the maximised window and clip to the monitor. You can’t make a maximised window straddle more than one monitor (to the best of my knowledge, anyway).

        1. Brian_EE says:

          I used to be able to maximize across multiple monitors (2, at least) on one of my older work machines. I think it was a graphics card driver extension though. It added a “wide maximize” icon just to the left of the standard maximize icon on all my program windows.

      3. Medinoc says:

        You send a WM_NCCALCSIZE to the window.

    2. Antonio Rodríguez says:

      Simple. Just don’t clip the screenshot if the window has a custom drawn border. Many window manager optimizations and special cases are disabled on custom windows, so why wouldn’t be this one?

      Anyway, Windows XP with visual styles enabled and Windows Vista (and later) with the Desktop Window Manager enabled already remove the sliver from screen (see the article linked by Raymond), so there is already code in the window manager to detect this case. Just apply it to the Alt+PrtSc handler.

      1. Ben Voigt says:

        I wonder if the window manager magic intercepts WM_NCHITTEST to exclude the overhang of maximized windows. If it does, that would be a fairly cheap way for custom screenshot tools to determine whether a window actually occupies a certain monitor, or does so only with an invisible overhang.

        1. Medinoc says:

          Since the DWM already intercepts WM_NCHITTEST over the entire non-client area, chances are high it does this kind of stuff too.

  2. Brian_EE says:

    Or, just use the Snipping Tool and capture exactly the portion of the screen(s) that you want. I use it so much I have it in the quick launch bar.

    1. The MAZZTer says:

      A simple hotkey is much faster, easier, and more accurate if you just want a window. If you are only interested in a portion of the window or screen then the snipping tool might be useful.

      Or just use Win+Shift+S which is a hotkey for a snipping tool built into Windows 10/OneNote. Quicker than the snipping tool but with most of the power (if you want to save it to a file Snipping Tool might be better).

      1. Steve says:

        Excellent, keyboard shortcut of the week!

      2. ender9 says:

        I wonder why they chose Win+Shift+S instead of Ctrl or Shift+PrintScreen (or even Ctrl+Alt+PrintScreen).

        1. Ian Yates says:

          Print screen is not on many laptop keyboards these days. They wanted new shortcuts to
          A.. Use the windows key
          B.. Possible to use on a surface keyboard (for example)

    2. Antonio Rodríguez says:

      It works for you, and that’s nice. But it may not work for everybody. For customer assistance, for example, you need to provide simple instructions that work in as many Windows versions as possible. Saying you can correct an edge case of Alt+PrtSc by switching to the Snipping Tool is like those annoying guys that, when you say “Help! Program X crashes in Windows XP!”, they solve it saying “Switch to Linux”.

      1. Brian_EE says:

        No, if anything it’s more like saying “Try Program Y, it does the same thing as X, but doesn’t crash”.

        However, my comment did begin with “Or” which implies options, not absolutes.

        1. morlamweb says:

          It’s more like “Open the Start menu/screen, do a search for snipping tool, click Snipping Tool, and use it to capture your window. It’s much more capable than ol’ alt-printscreen.” Sure, I could do all of that, or I could just tap the printscreen key. Which one will get the job done faster? *

          *Presuming that the machine has a physical keyboard. If not, substitute the equivalent button-or-tap screenshot combo for your device.

          1. Antonio Rodríguez says:

            Not only that. Snipping Tool was introduced in Windows 7, but there are still many Windows XP users (and even a few Windows 98 ones!), specially in niche applications (the ones more dependent on customer service provided by the maker). And Windows XP didn’t have Start Menu search, so the instructions to locate the tool would be different. Now, compare instructions taking into account all those variants to a simple “press the key labeled Print Screen and paste in a Word document” (Paint is a bit more complex to use, and less familiar to many office users).

            Or another example. You can try to instruct your Internet auntie by phone on how to use the Snipping Tool so you can read an error message, or you can say “take a picture of the screen with your cell phone and send me it through Whatsapp”.

            Yes, using a 30-year-old screen capture tool and pasting it in a Word document, or using a cell phone camera and Whatsapp may cringe us, tech users. But for many people, old and well-understood technology is a lot more effective.

  3. DWalker07 says:

    “On three of the sides, there is no content on the other side of the monitor”.

    That’s not true on my center monitor; there is a monitor to its left and one to its right!

    1. morlamweb says:

      I once had a Swordfish-like arrangement of four monitors on my desk, arrayed so that each monitor was bordered on two sides by another screen. It was impressive for it’s time, though I don’t miss it. Each monitor was rather small, so the total screen area was a bit less than my current dual-monitor setup.

      1. DWalker07 says:

        Swordfish-like? I don’t get it.

        1. Ben Voigt says:

          There was a movie titled ‘Swordfish’, he’s referring to the computer equipment depicted in that movie. https://www.google.com/search?q=swordfish+monitors&source=lnms&tbm=isch

  4. Adrian says:

    And now, with Windows 10, three of the four borders for typical top-level windows are already invisible (and the fourth is just hard-to-see).[1] So you’d think that this wouldn’t happen anymore. After all, a screenshot of a non-maximized window on Windows 10 doesn’t have extra pixels on the edges to account for the invisible resize border, so it seems weird that it still happens for a maximized one.

    [1]: Because who needs affordances? You should just know that the grab areas for resizing your window are just outside the window, unless you want to resize from the top, where the grab area is just inside the top edge of the title bar. Ah, there’s nothing like aiming the mouse at an invisible target; it’s the masochist’s version of Fitz’s Law!

    1. Ray Koopa says:

      The way the Windows 10 borders are designed is so annoying anyway. If you move the visible part to the very left edge of your screen, it’s X if actually negative. Applications remembering and clipping coordinates to positive values at launch then start the application several pixels offset to the screen edge and you have to move them again to fix it. Sigh.

      1. Neil says:

        I used to always tile my windows individually, but this looks really silly now they have invisible borders, so now I just give up and maximise them all.

  5. Colin says:

    All these solutions. Is this a test? Use the regular old PrtSc key and you’ll capture a screen shot of just the monitor. Which means just the visible portion of the maximized window. Which means no border.

    1. David Trapp says:

      I believe you will capture both monitors then. Not just the one you want.

      1. Chris Crowther says:

        Correct.

      2. Nick says:

        And if you have mixed resolutions and/or orientations, PrtSc captures an awful lot of black space that’s not on any monitor

        1. morlamweb says:

          That’s when you crop the image in an editor. It’s not much more work than going through the effort of opening the snipping tool and cropping the screen with it.

  6. Karellen says:

    Why do maximised windows even have borders? Instead of having them hang off the edge, why not just make them not exist? (Or exist, but with width 0?)

    1. David Trapp says:

      Because in the past, when nobody ever dreamt of multiple monitors and a few MB of RAM was a lot, it probably sounded like a nice solution to make the usable area on your 640×480 screen larger for a maximized window without adding special cases throughout the codebase.

      And if you change that now, you break tons of applications which have code that is based on that assumption that maximized Windows do hang over the edge because it was like this for decades.

  7. > But on the fourth side, the screen capture code sees that the pixels are still valid, and it includes them in the bitmap even though they’re on the wrong monitor.

    So, if you have a dual monitor setup and maximize a window on one screen, do you see its borders on the second screen?

    1. xcomcmdr says:

      No.

    2. David Trapp says:

      No because the borders will then be invisible (but logically they exist – they are simply transparent, so to speak). This way the old logic of maximized windows hanging over the edge still applies, but without visual nuisances.

  8. Smithers says:

    Failed to reproduce this at first because it is actually application dependant (on Windows 7). Sampling the applications I have currently have maximised, it didn’t capture the extra pixels for: Chrome, P4V, Paint, Kate. It did for Excel, Outlook and Visual Studio 2017.

    For added fun, my secondary monitor is taller than my primary, so the capture included extra pixels on three sides of the primary monitor, including black from the void area above the primary monitor.

Comments are closed.

Skip to main content