Hello,
I was writing a program that "sniffs" pixels and stores them into a file for future reference by other programs using the mouse cursor as the area where the pixel is to be retrieved. I was trying to use this program to get the Red, Green, and Blue values which GetPixel retrieves off of a game known as Diablo 2. I know this game to be rich in unique RGB colors due to its highly accelerated graphics. However, when I use my pixel sniffer, it seems to have a narrow scope of RGB identification and keeps retrieving the same RGB colors over and over again even though the RGB colors are actually very much different. I tried changing my resolution to 32 bit high but it had no effect. The same narrow scope of RGB colors came up again. Does anyone know how to fix this dilemma? For reference, here is the main coding for the pixel sniffer.
typedef struct tagPOINT { // pt
LONG x;
LONG y;
} POINT;
POINT pt;
BOOL get=GetCursorPos((LPPOINT(&pt)));
if (get == 0)
{
MessageBox(NULL, "Could not get mouse position", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
HWND handle=GetDesktopWindow();
if (handle == NULL)
{
MessageBox(NULL, "Could not get device content", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
HDC devcont=GetWindowDC(handle);
if (devcont == NULL)
{
MessageBox(NULL, "Could not get device content", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
COLORREF pixel=GetPixel(devcont, pt.x, pt.y);
if (pixel == CLR_INVALID)
{
MessageBox(NULL, "Could not extract pixel", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
LPCSTR name="sniffed.txt";
HANDLE file= CreateFile ( name
, GENERIC_READ | GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
if (file == INVALID_HANDLE_VALUE)
{
MessageBox(NULL, "Could not open sniffed.txt", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
DWORD charsWritten=0;
if ( !WriteFile ( (HANDLE(file))
, &pixel
, sizeof(pixel)
, &charsWritten
, NULL
)
)
{
MessageBox(NULL, "Could not write to sniffed.txt", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
I was writing a program that "sniffs" pixels and stores them into a file for future reference by other programs using the mouse cursor as the area where the pixel is to be retrieved. I was trying to use this program to get the Red, Green, and Blue values which GetPixel retrieves off of a game known as Diablo 2. I know this game to be rich in unique RGB colors due to its highly accelerated graphics. However, when I use my pixel sniffer, it seems to have a narrow scope of RGB identification and keeps retrieving the same RGB colors over and over again even though the RGB colors are actually very much different. I tried changing my resolution to 32 bit high but it had no effect. The same narrow scope of RGB colors came up again. Does anyone know how to fix this dilemma? For reference, here is the main coding for the pixel sniffer.
typedef struct tagPOINT { // pt
LONG x;
LONG y;
} POINT;
POINT pt;
BOOL get=GetCursorPos((LPPOINT(&pt)));
if (get == 0)
{
MessageBox(NULL, "Could not get mouse position", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
HWND handle=GetDesktopWindow();
if (handle == NULL)
{
MessageBox(NULL, "Could not get device content", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
HDC devcont=GetWindowDC(handle);
if (devcont == NULL)
{
MessageBox(NULL, "Could not get device content", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
COLORREF pixel=GetPixel(devcont, pt.x, pt.y);
if (pixel == CLR_INVALID)
{
MessageBox(NULL, "Could not extract pixel", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
LPCSTR name="sniffed.txt";
HANDLE file= CreateFile ( name
, GENERIC_READ | GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
if (file == INVALID_HANDLE_VALUE)
{
MessageBox(NULL, "Could not open sniffed.txt", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
DWORD charsWritten=0;
if ( !WriteFile ( (HANDLE(file))
, &pixel
, sizeof(pixel)
, &charsWritten
, NULL
)
)
{
MessageBox(NULL, "Could not write to sniffed.txt", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}