Hey all, I'm looking for a way to be able to read the color data at say pixel (0,5) on the screen and check it's color. Is there a way to do this that isn't window dependent? and if not, how do you do it? Thanks, John
Printable View
Hey all, I'm looking for a way to be able to read the color data at say pixel (0,5) on the screen and check it's color. Is there a way to do this that isn't window dependent? and if not, how do you do it? Thanks, John
GetPixel() on the DC.
Not the best idea.
Ok, I tried that, however I need to access the color of a pixel in a separate thread than the one that calls the function. Should I pass in HWND_TOPMOST for the hwnd parameter?
Give this a try with the code from your other post.
Code:__declspec(dllexport) LRESULT CALLBACK KeyboardEvent (int nCode, WPARAM wParam, LPARAM lParam)
{
MOUSEHOOKSTRUCT * pMouseStruct = (MOUSEHOOKSTRUCT *)lParam;
if (pMouseStruct != NULL)
printf("Mouse position X = %d Mouse Position Y = %d\n", pMouseStruct->pt.x,pMouseStruct->pt.y);
HWND window = GetForegroundWindow();
HDC hDC = GetDC(window);
COLORREF rgb = GetPixel(hDC, pMouseStruct->pt.x, pMouseStruct->pt.y);
COLORREF red = GetRValue(rgb);
COLORREF green = GetGValue(rgb);
COLORREF blue = GetBValue(rgb);
printf("%02X %02X %02X\n",red,green,blue);
return CallNextHookEx(hMouseHook,
nCode,wParam,lParam);
}
Actually guys, thanks for the help, but I found out how to get the handle to the window I was targetting anyway. Thanks :)