i get an error
"undefined identifier 'hwnd'"
i get an error
"undefined identifier 'hwnd'"
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
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
and from msdn:Code:sprintf(chPixColor,"R=%d G=%d B=%d hex=%p",GetRValue(pixColor),GetGValue(pixColor),GetBValue(pixColor),pixColor);
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 08:33 PM.
All Your Base Are Still Belong to Someone!!!
And you Remember that!!!
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.
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!!!
#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.
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!!!
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!!!
alternately you could do something like this
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.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; }
All Your Base Are Still Belong to Someone!!!
And you Remember that!!!
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.
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!!!