Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetPixel function returns CLR_INVALID

Status
Not open for further replies.

smoothie1248

Programmer
Dec 31, 2003
1
US
Hi,
I am trying to use GDI GetPixel function. I first get the DC using
hdc = GetDC(hWnd);
then call GetPixel(hdc,x,y); function. However GetPixel returns -1 which obviously shows that GetPixel cannot read from the dc. I found that I should use GetDeviceCaps to check whether the dc is capable of giving this information. What if it is not? how can I read the RGB values of a position in the window?

Thank you.
 
Use GetLastError() to get more info when returns CLR_INVALID.
Maybe is enough to retrive RGB using CDC::GetTextColor() , CDC::GetBkColor() and after that CDC::GetNearestColor().
-obislavu-
 
I believe you should ckeck if that pisel is inside the client area of window. Use first GetClientRect. After that check if the point (x, y) is inside of that rect.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top