how can i get the pixel of the covered window

how can i get the pixel of the covered window  using -'c++,c,winapi'

I am using Visual Studio 2008 on Windows XP and studying C++.
I am curious about the getting pixel from desktop.
Can I get the screen pixel with GetPixel function in the case that the window is covered with another window?  In the status of my window being covered, I was trying to call the GetPixel:

GetPixel(hdc, x, y);

But this call dosen't retrieve the pixel of the original window but the covering window or other color one.  

How can I get the pixel of the covered window?

I add my code as the following ...

VOID GetDisplay(HWND& hwnd, RECT& area, COLORREF (*display)[1000]) {
    HDC hdc=GetDC(hwnd);
    for(INT x=area.left;x<=area.right;x++) {
        for(int;y<=area.bottom;y++) {
            display[x][y]=GetPixel(hdc, x, y);
    ReleaseDC(hwnd, hdc);


SetWindowPos(hwnd, HWND_TOPMOST, 300, 300, 500, 350, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
//EnableWindow(hwnd, TRUE);

GetDisplay(hwnd, within_wall, display);//trouble

The problem is causing on the GetPixel in GetDisplay.  GetPixel is returning the pixel color of the covering window.

asked Sep 9, 2015 by TawnyaHaskin
0 votes

1 Answer

0 votes

There's no 100% way to do it, as windows are not required to, and generally don't, draw obscured areas. You will not be able to make the desktop a foreground window of course. And focus has no effect on visibility, as someone has mentioned SetFocus. That would be ineffective.

I have seen proposals to use WM_PRINT to access obscured pixels. Again this is not guaranteed, but the desktop window is pretty specific so if you get that to work, I guess it'll be somewhat reliable.

For more on this, see: PrintWindow.

For what it's worth, GetPixel is extremely slow. You'll probably notice a performance problem in your code. You'll get much better performance by using methods like GetDIBits.

answered Sep 9, 2015 by MylesPmwhibx