GetPixel?

I don't know why my function doesn't print out in RGB format, but it prints out very hug number like 3435973836..

int xScreen = GetSystemMetrics(SM_CXSCREEN);
int yScreen = GetSystemMetrics(SM_CYSCREEN);

pixelx = (DWORD)((65535/xScreen) * 787);
pixelY = (DWORD)((65535/yScreen) * 528);

HDC hdc = GetDC(windowNameCC);
COLORREF color = GetPixel(hdc, pixelX, pixelY);

anybody knows why?
[441 byte] By [mase] at [2007-11-20 11:18:47]
# 1 Re: GetPixel?
If you want to obtain RGB values you must to use this:

BYTE nRedValue, nGreenValue, nBlueValue;
nRedValue = GetRValue(color);
nGreenValue = GetGValue(color);
nBlueValue = GetBValue(color);

The "3435973836" value is the RGB value not R value, G value and B value ;)
juanpast at 2007-11-10 22:26:01 >
# 2 Re: GetPixel?
If you want to obtain RGB values you must to use this:

BYTE nRedValue, nGreenValue, nBlueValue;
nRedValue = GetRValue(color);
nGreenValue = GetGValue(color);
nBlueValue = GetBValue(color);

The "3435973836" value is the RGB value not R value, G value and B value ;)

It's a RGB values ? I didn't know that. I was referring to the hexa digit like 0xffffff, but nevermind I misunderstood on my side. Thanks you for your respond.
mase at 2007-11-10 22:27:01 >
# 3 Re: GetPixel?
3435973836 is 0xcccccccc which sounds suspiciously like uninitialized data. Where did you come up with those calculations for pixelX and pixelY? I can almost guarantee you that they will be well off the viewing area of any reasonable monitor. You don't even show the code that you are having a problem with - printing the color value. I don't think that anyone is going to be able to help you successfully with what you have posted. Can you explain further?
0xC0000005 at 2007-11-10 22:27:54 >
# 4 Re: GetPixel?
3435973836 is 0xcccccccc which sounds suspiciously like uninitialized data. Where did you come up with those calculations for pixelX and pixelY? I can almost guarantee you that they will be well off the viewing area of any reasonable monitor. You don't even show the code that you are having a problem with - printing the color value. I don't think that anyone is going to be able to help you successfully with what you have posted. Can you explain further?

ok sure, I can further explain what I woud like to do. Basically I'm using console application sending mouse click to select the menu in another application. There is one of the menu that splits into two categories, but they display under the same window one at a time. Since my knowledge in C++ is just basic, so I use the simple method to differentiate those two menus by comparing certain pixel location. For example two categoryA and B, so in the category A it has white pixel color on the position where category B doesn't have so that is why earlier I used the function to get GetPixel(), but the function returns very hug number. I want it to return in hexa digit 0xfffff. The integer value from the systemmetrics calculation is so hug so I'm still having doubt that the position is not on my current monitor screen area because I'm running 1280x1024 screen resolution, and the number is so big 3435973836.

This is the function that produce that number:
COLORREF color = GetPixel(hdc, pixelX, pixelY);

void selectMenu(int x, int y)
{

int pixelX = 0;
int pixelY = 0;

mouseMoveMotion(x + 3, y); //increment x-axis to show motion moving
delayProccess();
mouseMoveMotion(x + 10, y);//increment x-axis to show motion moving
delayProccess();
mouseMoveLeftClick(x, y); //select Ethernet Wireless settings
delayProccess();

HWND windowNameCC = FindWindow(NULL, TEXT("Device Options"));

//check to make sure it's successfully retrieve the handle if(windowNameCC == NULL)
{

MessageBox(NULL, TEXT("Can not find Device Options window"), TEXT("Error!"), MB_ICONSTOP | MB_OK);
return;
}

//screen resolution
int xScreen = GetSystemMetrics(SM_CXSCREEN);
int yScreen = GetSystemMetrics(SM_CYSCREEN);

//which tab is displaying?
pixelX = (DWORD)((65535/xScreen) * 787);
pixelY = (DWORD)((65535/yScreen) * 528);
HDC hdc = GetDC(windowNameCC);
COLORREF color = GetPixel(hdc, pixelX, pixelY);

BYTE nRedValue, nGreenValue, nBlueValue;
//integer value 255 = ff -white
//integer value 255 = ff -white
//integer value 255 = ff -white
//integer value 248 = f8
//integer value 248 = f8
//integer value 248 = f8
nRedValue = GetRValue(color); //this will get integer value representing for red color
nGreenValue = GetGValue(color); //this will get integer value representing for green color
nBlueValue = GetBValue(color); //this will get integer value representing for blue color
cout<<"\nRed: "<<nRedValue<<endl;
cout<<"\nGreen: "<<nGreenValue<<endl;
cout<<"\nBlue: "<<nBlueValue<<endl;

if(xScreen == 800 && yScreen == 600)
{

cout<<"\nhahaha";

}
else if(xScreen == 1280 && yScreen == 1024)
{


cout<<"\nhahaha";

}
}
mase at 2007-11-10 22:29:05 >
# 5 Re: GetPixel?
OK, but my first question is where did you come up with those calculations?
pixelX = (DWORD)((65535/xScreen) * 787);
pixelY = (DWORD)((65535/yScreen) * 528);
For a 1280x1024 monitor (which you are checking for below) those values will be 40137 and 33264 which are well off the screen as I said.
0xC0000005 at 2007-11-10 22:30:03 >
# 6 Re: GetPixel?
I saw the code from other thread in this forum using the systemmetric to assist the mouse movement. For example if I want to move my mouse to this location for example 187,395, and I use systemmetric to get screen resolution and use that calcuation you just mentioned then the mouse moves specifically to that position, but when I don't use that calculation my mouse doesn't move to that specific point.

pixelX = (DWORD)((65535/xScreen) * 787);
pixelY = (DWORD)((65535/yScreen) * 528);

I don't know what is 65535, but since it works with my mouse movement so I keep using it although I tried to search for it, but came up nothing. The number 787, and 528 are my x and y position where I want to get the pixel color from.

Since my position is way off like you said then should I do if I want to get the pixel color at this screen position 787,528?

by the way my code above missing the if-statement:

HWND windowNameCC = FindWindow(NULL, TEXT("Device Options"));

//check to make sure it's successfully retrieve the handle
if(windowNameCC == NULL)
{

MessageBox(NULL, TEXT("Can not find Device Options window"), TEXT("Error!"), MB_ICONSTOP | MB_OK);
return;
}
mase at 2007-11-10 22:31:02 >
# 7 Re: GetPixel?
Sorry, I don't know what mouse mouseMoveMotion() is, but if you want the pixel color at 787, 528 then you would do this:

COLORREF color = GetPixel(hdc, 787, 528);
0xC0000005 at 2007-11-10 22:31:59 >
# 8 Re: GetPixel?
Sorry, I don't know what mouse mouseMoveMotion() is, but if you want the pixel color at 787, 528 then you would do this:

COLORREF color = GetPixel(hdc, 787, 528);

moveMoveMotion is just my function that I made up, just sending mouse from point to point without applying mouse click.

I tried this before I used the systemmetrics, but it didn't work.
COLORREF color = GetPixel(hdc, 787, 528);

base on the cout below, they don't display any output to screen as I check on the DOS screen.
cout<<"\nRed: "<<nRedValue<<endl;
cout<<"\nGreen: "<<nGreenValue<<endl;
cout<<"\nBlue: "<<nBlueValue<<endl;

is it because those three variables are declared in byte thus I can't display out?
mase at 2007-11-10 22:33:03 >