-
GetPixel return value
I have an example in petzold (chapter 5, basic drawing) that was something like this (to implement the GetPixel function):
crColor = GetPixel(hdc, x, y)
I know what the parameters are for GetPixel and I understand what the function does, but what type is the return value to assign to?
Thanks.
--Garfield the Programmer
-
It's a COLORREF, which is a 32bit variable packed with a RGB value. The bytes are 00BBGGRR.
-
So I would use a long int data type? BTW, what is the equivalent of long int in Windows programming?
Thanks.
--Garfield
-
Or would the data type be COLORREF? Would it be this:
Code:
COLORREF crColor;
crColor = GetPixel(hdc, x, y);
Thanks.
--Garfield
-
Oh (sorry for all this posting), can you still answer my 'long int' question? Thanks.
-
Yes, COLORREF is a typedef of DWORD, which is a typedef of unsigned long, but you'd use a COLORREF variable so anyone looking at your code knows what it is. Also, if the sizeof unsigned long changes then COLORREF may no longer be a typedef of unsigned long, so if you were compliing code in this enviroment it may not be correct (in future versions of windows/win32api).
There are lots of different typedef's of a long int/unsigned long. LONG and ULONG are the most obvious, but if you're not sure there's nothing stopping you using a normal C long. Also if you're using MSVC and you enable the option to generate browse info anytime you're not sure of a typedef(or any function, define, etc), place the caret on it and press F12 and you'll be shown the header file where it's typedef'd.
-
-
Ahhhh, F12.
(Beats the right click & go to definition/ref)
My new friend. Come and play with me and F1.
(You learn somethig new everyday. Now I can go home and forget it)