• Having trouble with GetPixel
    1 replies, posted
I'm having trouble using GetPixel. What I'm trying to do is get the Paint window and get the red, green, and blue values of a certain location. But when I try to view the values there all 255. I know this can be right because the area is not white. Here's the code: [code] #include <Windows.h> #include <iostream> int main() { HWND window = FindWindow(NULL,"untitled - Paint"); HDC hdc = GetDC(window); COLORREF color = GetPixel(hdc,100,100); std::cout<<color<<"\n"; std::cout<<(int)GetRValue(color)<<" "<<(int)GetGValue(color)<<" "<<(int)GetBValue(color); } [/code] Also, I know the window is the Paint window because I tried sending a message to it to close the window and that worked. So at the moment I'm not sure what the problem is. Please help if it's not too much trouble and thanks.
Well it's not really returning white(255) pixels, it's returning a COLORREF that equals CLR_INVALID. [QUOTE]Not all devices support GetPixel. An application should call GetDeviceCaps to determine whether a specified device supports this function. A bitmap must be selected within the device context, otherwise, CLR_INVALID is returned on all pixels. [/QUOTE] Maybe you have to find the child window of the actual canvas.
Sorry, you need to Log In to post a reply to this thread.