Thread: COLORREF GetPixel(); Help

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    43

    Question COLORREF GetPixel(); Help

    [UPDATE]
    Ok can some one help me get this code working im using Dev-C++ and windows XP

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <windows.h>
    int main()
    {
    DWORD color = GetPixel(hdc, x, y);
    unsigned int r = GetRValue(color);
    unsigned int g = GetGValue(color);
    unsigned int b = GetBValue(color);
    
    cout << "red: " << r << endl;
    cout << "green: " << g << endl;
    cout << "blue: " << b << endl;
    system("pause");
    return 0;
    }
    Last edited by JordanCason; 11-19-2007 at 08:59 PM.

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    First, you need to tell us what computer, operating system, and compiler you are using. (There is no color or graphics in Standard ANSI/ISO C++, so it depends on your platform.)

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    All right than thanks ill remember that well I’m using Dev-C++ on windows XP.

    Found this at msdn and it works just cant get it all to work to gather to make something like that which I explained before.
    http://msdn2.microsoft.com/en-us/library/ms532282.aspx
    Last edited by JordanCason; 11-19-2007 at 04:12 PM.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    43

    Thumbs up

    bumb because of UPDATE and dident wont to start a new thread

  5. #5
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    You need to defined hdc, x, and y, and set each to valid values, otherwise your code won't even compile. What are you trying to do?
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    I’m kind of working on making something like a little color picker for the CMD not a real purpose for it besides making a goal for me to work for. Works best that way for me but I am also fallowing a book at the same time. But ya I tried that it didn’t work properly because of my mistake but I will try again. O yes and what exactly is hdc that would help to. Thanks ill let you know if I get the code working thanks.

    ya I think if some one could clear up what hdc is that I will beable to get this working thaks
    Last edited by JordanCason; 11-19-2007 at 10:17 PM.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You use GetPixel to get the colour of the pixel in some Device Context at some location.
    What Device Context do you want to get a pixel's colour from, and where on it?

    Or would you simply like a random colour?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Registered User
    Join Date
    Nov 2007
    Posts
    43

    Thumbs up

    Thank you for your Reply but I have figured it out I was havening a link error "undefined reference to getpixel@12" and I fixed it by going to project > Project options > load object file and loading "libgdi32.a".

    Here is my code for any one els trying to get this stuff to work took me for ever lol.
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <windows.h>
    int main()
    {
    int x,y;
        cout << "Enter coordanets: ";
             cin >> x;
             cin >> y;
                 HDC hdc = GetDC(NULL);
                 DWORD color = GetPixel(hdc, x, y);
                 unsigned int r = GetRValue(color);
                 unsigned int g = GetGValue(color);
                 unsigned int b = GetBValue(color);
        cout << "red: " << r << endl;
        cout << "green: " << g << endl;
        cout << "blue: " << b << endl;
    cin.get();
    cin.ignore();
    return 0;
    }
    I do have a new task if any of you would like to help me. I’m working on making the mouse move to a color pixel bye using this code if you could help with that it would be grate thanks.


    Also im stuck with this one see if any of you guys can help
    Code:
    #include <iostream>
    #include <windows.h>
    #include <stdlib.h>
    
    
    using namespace std;
    
    int main(int x, int y)
    {
    HANDLE mouseup = mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
    WaitForSingleObject(mouseup, INFINITE);
    cout << "should never appeared";
    }
    the goal im trying to reach with this is to wait untill the left buttin on the mouse lifts up.
    Last edited by JordanCason; 11-20-2007 at 07:27 AM.

  9. #9
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Drop the .h from iostream thats an old header. Use
    Code:
    #include <iostream>
    Also do not use system() calls unless you really need to. They are unsafe. Use

    Code:
    cin.get();
    cin.ignore()
    In place to act the same as system("pause");
    Double Helix STL

  10. #10
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    Thanks! and I updated it : )

  11. #11
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by JordanCason View Post
    Code:
    int main(int x, int y)
    I don't believe that is a valid function signature for main.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetPixel and CreateDC help. (winapi)
    By OpiateDelusion in forum Windows Programming
    Replies: 6
    Last Post: 08-19-2007, 08:15 AM
  2. GetPixel()
    By thedoofus in forum C Programming
    Replies: 1
    Last Post: 04-30-2006, 08:40 PM
  3. GetPixel Function
    By Coder87C in forum Windows Programming
    Replies: 13
    Last Post: 11-19-2004, 11:50 PM
  4. GetPixel with DISPLAY
    By phil_drew in forum Windows Programming
    Replies: 2
    Last Post: 04-01-2003, 04:57 PM
  5. GetPixel return value
    By Garfield in forum Windows Programming
    Replies: 7
    Last Post: 11-14-2001, 01:18 AM