Repository: python-pillow/Pillow

Issue:
PIL.ImageGrab.grab() doesn't "see" all windows
Code
```python
im = PIL.ImageGrab.grab()
im.save('2.png')
```

Here is what actually displayed:
![image](https://user-images.githubusercontent.com/9055497/26917911-ac2b2220-4c38-11e7-80bf-15e8313728d8.png)

Here is the screenshot of PIL:
![screenshot_27](https://user-images.githubusercontent.com/9055497/26918031-03c6893e-4c39-11e7-8b87-d89a9c056f5e.png)

Pillow version==4.1.0
This is relevant for different pop ups and menus.

According to @glitchassassin (from pyautogui):

 

> Looks like this is a limitation of Pillow, using SRCCOPY instead of SRCCOPY | CAPTUREBLT in the call to BitBlt.



Discussion:
There's the `SRCCOPY`: 

https://github.com/python-pillow/Pillow/blob/6e7553fb0f12025306b2819b9b842adf6b598b2e/display.c#L349
See [BitBlt documentation](https://msdn.microsoft.com/en-us/library/windows/desktop/dd183370(v=vs.85).aspx):

> *CAPTUREBLT*
>
> Includes any windows that are layered on top of your window in the resulting image. By default, the image only contains your window. Note that this generally cannot be used for printing device contexts.

For the desktop window, "windows that are layered on top" include popups, tooltips, menus, and perhaps some other specialty windows that have to always appear in the foreground. OR-ing the `CAPTUREBLT` flag with the `SRCCOPY` flag guarantees that these windows will also be captured.

Note that not all applications may wish to capture these additional details, so for backwards compatibility, it may be worth adding an argument to the method definition to specify "capture overlays".
Hello, I'm having the same problem, but I don't see any display.c file in the Pillow directory as hugovk mentioned and also didn't found the call to BitBlt.
I'm trying to screencapture with pyautogui and saw that not all the windows on the screen were captured and also saw that this could be an issue from pillow.

I've installed with pyautogui with PIP, and this only installs the PIL folder and not all the files in the parent directory, as it is [here](https://github.com/python-pillow/Pillow/tree/6e7553fb0f12025306b2819b9b842adf6b598b2e).
I have Pillow     5.2.0

Do you know how to fix this?
For the record, display.c is located at https://github.com/python-pillow/Pillow/blob/master/src/display.c. @edanca was likely having trouble finding it because it was moved into the 'src' directory since [earlier comment](https://github.com/python-pillow/Pillow/issues/2569#issuecomment-307075021).
I've created PR #3808 to address this.

Resolving patch:
diff --git a/src/PIL/ImageGrab.py b/src/PIL/ImageGrab.py
--- a/src/PIL/ImageGrab.py
+++ b/src/PIL/ImageGrab.py
@@ -29,7 +29,7 @@
     import subprocess
 
 
-def grab(bbox=None):
+def grab(bbox=None, include_layered_windows=False):
     if sys.platform == "darwin":
         fh, filepath = tempfile.mkstemp('.png')
         os.close(fh)
@@ -38,7 +38,7 @@ def grab(bbox=None):
         im.load()
         os.unlink(filepath)
     else:
-        size, data = grabber()
+        size, data = grabber(include_layered_windows)
         im = Image.frombytes(
             "RGB", size, data,
             # RGB, 32-bit line padding, origin lower left corner


Test patch:
diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py
--- a/Tests/test_imagegrab.py
+++ b/Tests/test_imagegrab.py
@@ -9,8 +9,11 @@
     class TestImageGrab(PillowTestCase):
 
         def test_grab(self):
-            im = ImageGrab.grab()
-            self.assert_image(im, im.mode, im.size)
+            for im in [
+                ImageGrab.grab(),
+                ImageGrab.grab(include_layered_windows=True)
+            ]:
+                self.assert_image(im, im.mode, im.size)
 
         def test_grabclipboard(self):
             if sys.platform == "darwin":