I have searched high and low for a definitive answer to this, and I cannot find one (that I understand)
The windows function GetPixel takes 3 arguments (HDC, int, int). Both ints represent a coordinate in the devive context, but are measured in logical units, x =
The x-coordinate, in logical units, of the pixel to be examined.
What I need to pass it, and it to return value of, is the value of the pixel at coordinates of screen in pixels.
There are many answers aroun which tell me to use LPtoDP function to convert.
My problem is, I just cannot figure out how to use this function from the documentation, it may be a brain hiccup, but just does not make sense to me.
I'm hoping someone might have the time to help me to understand and use it, to attain my goal.
Here is some code explaining my endgame.
DWORD GetPixelColor(int x,int y){
HDC hdc = GetDC(NULL); // device context of whole screen/desktop
DWORD pix = GetPixel(hdc,x,y); // here I want the color of the pixel at x, y (in pixels)
if (pix == CLR_INVALID) {
return -1;
}
return pix;
}
Now that code, at first seems to work but it simply does not.
GetPixelColor(1,1);
for example will return incorrect color, it will return incorrect color right up to about x = 9 and y = 11. It is really quite odd, and I believe it to be this logical units thing. After points say (8,12) it appears to return correct pixel color :/
And that is where I am stuck, not being able to figure out how to use LPtoDO (or is it DPtoLP) I don't know..
Most specifically the second parameter
lpPoints [in, out]
A pointer to an array of POINT structures. The x-coordinates and y-coordinates contained in each of the POINT structures will be transformed.
Appreciate any help that may be given.