As mentioned in a previous post, you want the GetPixel function to be executed from the Win32 API.
GetPixel is inside gdi32.dll, so if you have the proper environment settings, you must enable windows.h (including wingdi.h) and you must be golden.
If you have minimal environment settings for any reason, you can also directly use LoadLibrary on gdi32.dll.
The first GetPixel parameter is a device context handle that can be obtained by calling the GetDC function (which is also available through <windows.h> ).
A basic example that loads GetPixel from a DLL and prints the color of the pixel, wherever your cursor is, looks like this.
#include<windows.h> #include<stdio.h> int main(int argc, char** argv) { FARPROC pGetPixel; HINSTANCE _hGDI = LoadLibrary("gdi32.dll"); if(_hGDI) { pGetPixel = GetProcAddress(_hGDI, "GetPixel"); HDC _hdc = GetDC(NULL); if(_hdc) { POINT _cursor; GetCursorPos(&_cursor); COLORREF _color = (*pGetPixel) (_hdc, _cursor.x, _cursor.y); int _red = GetRValue(_color); int _green = GetGValue(_color); int _blue = GetBValue(_color); printf("Red: 0x%02x\n", _red); printf("Green: 0x%02x\n", _green); printf("Blue: 0x%02x\n", _blue); } FreeLibrary(_hGDI); } return 0; }
syllogism
source share