0

I'm trying to use Windows APIs to take a screen shot of a window. Here is my current code:

//Grab the window
HWND window = me;//GetForegroundWindow();
HDC context = GetDC(window);
RECT windowRect;
GetWindowRect(window, &windowRect);
int w = windowRect.right-windowRect.left;
int h = windowRect.bottom-windowRect.top;

//Copy the data
for (int y=0;y<h;y++)
    for (int x=0;x<w;x++)
    {
        COLORREF color = GetPixel(context, x,y);
        std::cout<<color<<std::endl;
    }

The width and height return correctly (as well as the window location), but the color is always 0xFFFFFF (white).

It seems like it should be fairly easy as in windows taking a screenshot of a window is simply alt+shift+Print Screen

Stephen Lin
  • 5,470
  • 26
  • 48
Jason
  • 13,563
  • 15
  • 74
  • 125
  • 1
    Taking a screenshot of a window is alt+Print Screen. I'm not sure what the shift in there is for, but just alt has always worked for me. – chris Mar 02 '13 at 02:42
  • http://stackoverflow.com/questions/7292757/how-to-get-screenshot-of-a-window-as-bitmap-object-in-c – Jason Mar 02 '13 at 02:45
  • 1
    Use BitBlt(). You could just copy/paste the [SDK sample code](http://msdn.microsoft.com/en-us/library/windows/desktop/dd183402%28v=vs.85%29.aspx) – Hans Passant Mar 02 '13 at 04:02
  • Thanks guys. I did search stack overflow before I posted, but most of what I found was related to OS X and mobile devices. – Jason Mar 02 '13 at 13:18

0 Answers0