GetPixel return value

This is a discussion on GetPixel return value within the Windows Programming forums, part of the Platform Specific Boards category; I have an example in petzold (chapter 5, basic drawing) that was something like this (to implement the GetPixel function): ...

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    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
    1978 Silver Anniversary Corvette

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    It's a COLORREF, which is a 32bit variable packed with a RGB value. The bytes are 00BBGGRR.
    zen

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    So I would use a long int data type? BTW, what is the equivalent of long int in Windows programming?

    Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Or would the data type be COLORREF? Would it be this:
    Code:
    COLORREF     crColor;
    
    crColor = GetPixel(hdc, x, y);
    Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Oh (sorry for all this posting), can you still answer my 'long int' question? Thanks.
    1978 Silver Anniversary Corvette

  6. #6
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    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.
    zen

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Thanks, zen!
    1978 Silver Anniversary Corvette

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    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)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  2. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 05:10 AM
  3. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM
  5. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21