Click here to Skip to main content
15,665,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get the pixel color of a specified coordinate point outside my application window. So, since hwnd specifies my window to be targeted, then all i should do is use getdc function and pass my hwnd as parameter.

But what if I want a coordinate point from outside my application window? I already put the code but all I need is to know.

What parameter value to pass to getdc to make it target the screen from outside my application window, and my whole program is just to handle one window, with the area outside it, I am not using multiple windows in the same application.

What I have tried:

HDC targetArea = GetDC (???);// what should I //specify here as parameter ?

COLORREF colorValue;
colorValue = GetPixel(targetArea,500,400);
Updated 26-Mar-23 14:40pm

1 solution

You can use GetDC on the NULL window to get a device context for the whole screen, and can follow that up with a call to GetPixel:

HDC dc = GetDC(NULL);
COLORREF cr = GetPixel(dc, x, y);
ReleaseDC(NULL, dc);
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900