help on pixels

This is a discussion on help on pixels within the Windows Programming forums, part of the Platform Specific Boards category; i get an error "undefined identifier 'hwnd'"...

  1. #16
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    i get an error

    "undefined identifier 'hwnd'"

  2. #17
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    For your purposes, you can use NULL or 0 as the first parameter to MessageBox in place of hwnd.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #18
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    hah, oh yeah, gues i shoulda edited it a little more for general needs. if you want to see the hex value then you can use a statement kinda like this

    Code:
    sprintf(chPixColor,"R=%d G=%d B=%d hex=%p",GetRValue(pixColor),GetGValue(pixColor),GetBValue(pixColor),pixColor);
    and from msdn:
    The low-order byte contains a value for the relative intensity of red; the second byte contains a value for green; and the third byte contains a value for blue. The high-order byte must be zero. The maximum value for a single byte is 0xFF.
    Last edited by AtomRiot; 07-14-2004 at 09:33 PM.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  4. #19
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    i have some great news and some bad news. the great news is it compiles and runs without error. the bad news is everytime it is run, no matter what coordinates are put in, the values are r = 255, g = 255, b = 255

    by the way thx all for helping me out.

  5. #20
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    i had that problem once when i was trying to point at an hdc that was specified in another function, lets see your source and see where the problem is
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  6. #21
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    #include <cstdio>
    #include <windows.h>
    #include <string.h>
    #include <stdlib.h>
    #pragma comment(lib, "gdi32.lib")

    int main()
    {
    COLORREF clr;
    HDC hdcScrn;
    POINT pt;

    GetCursorPos(&pt);
    hdcScrn=CreateDC("DISPLAY",0,0,0);
    clr=GetPixel(hdcScrn,pt.x,pt.y);
    DeleteDC(hdcScrn);

    COLORREF pixColor = GetPixel(hdcScrn,600,400);
    SetCursorPos(600,400);
    char chPixColor[1024];
    sprintf(chPixColor,"R=%d G=%d B=%d",GetRValue(pixColor),GetGValue(pixColor),GetB Value (pixColor));
    MessageBox(NULL,chPixColor,"Pixel Color @ x=13 y=13",0);

    return 0;
    }

    -----

    all the includes are cuz i kept getting errors so i just put a bunch in so i wouldn't have to worry about which were the right ones. i added a SetCursorPos so i could see what point it was getting the color from.

  7. #22
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    ok, the problem is that you delete your dc then try to get a pixel from it. move the call down after you get the pixel and try that
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  8. #23
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    also make sure that there is not white under point 600 400 or it will return 255 255 255 because that is white anyway.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  9. #24
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    alternately you could do something like this

    Code:
    #include <cstdio>
    #include <windows.h> 
    #include <string.h> 
    #include <stdlib.h> 
    #include <conio.h>
    #pragma comment(lib, "gdi32.lib")
    
    int main()
    {
    COLORREF pixColor;
    HDC hdcScrn;
    POINT pt;
    char chPixColor[1024];
    char chMouseLoc[1024];
    GetCursorPos(&pt);
    while(pt.x<1000)
    {
     GetCursorPos(&pt);
     hdcScrn=CreateDC("DISPLAY",0,0,0);
     pixColor = GetPixel(hdcScrn,pt.x,pt.y);
     sprintf(chPixColor,"R=%d G=%d B=%d",GetRValue(pixColor),GetGValue(pixColor),GetBValue (pixColor));
     sprintf(chMouseLoc,"Pixel Color @ x=%d y=%d",pt.x,pt.y);
     MessageBox(NULL,chPixColor,chMouseLoc,0);
    }
    DeleteDC(hdcScrn);
    return 0; 
    }
    that will get the mouse x and y and get the color and will do so as long as your mouse x is less than 1000. my resolution is set at 1280x1024 so my mouse x can go past 1000 but if yours is lower than that then you will have to stop the program using task manager so if you use this then be sure to change the size to fit your screen. also you can just use the spacebar to hit ok and move the mouse wherever.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  10. #25
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    ok thx a lot atomriot you've been a lot of help and everything works very well.

    now i can move on to my fun little programs.

  11. #26
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    glad to have been of assistance. I guess that is what these boards are for because I was once in your position in this area. and I still am in other areas.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Manipulating single LCD pixels
    By finnepower in forum Networking/Device Communication
    Replies: 3
    Last Post: 02-22-2008, 08:45 PM
  2. Trying to write individual pixels to the screen
    By IanC in forum C++ Programming
    Replies: 3
    Last Post: 04-14-2004, 01:49 PM
  3. bitmap pixels???????????
    By SuperNewbie in forum Windows Programming
    Replies: 2
    Last Post: 03-23-2004, 01:53 AM
  4. creating image from pixels stored in file
    By Kristian25 in forum Windows Programming
    Replies: 3
    Last Post: 01-21-2003, 02:08 PM
  5. Algo needed for 'Fit to page'
    By Unregged in forum Windows Programming
    Replies: 6
    Last Post: 10-03-2002, 08:09 AM

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