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:
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