I need a quick command line application to return the pixel color under the mouse cursor.
How can I build this in VC ++, I need something similar to this , but ideally not in .NET, so it can be run many times per second?
From head to head, right:
#include <stdio.h> #include <Windows.h> int main(void) { POINT p; COLORREF color; HDC hDC; BOOL b; // Get the device context for the screen hDC = GetDC(NULL); if (hDC == NULL) return 3; // Get the current cursor position b = GetCursorPos(&p); if (!b) return 2; // Retrieve the color at that position color = GetPixel(hDC, px, py); if (color == CLR_INVALID) return 1; // Release the device context again ReleaseDC(GetDesktopWindow(), hDC); printf("%i %i %i", GetRValue(color), GetGValue(color), GetBValue(color)); return 0; }
ETA: Appears to work, at least for me.
ETA2: Added some error checking
ETA3: Commented code, compiled executable, and Visual Studio solution can be found in my SVN repository .
Source: https://habr.com/ru/post/1313305/More articles:How to join jagged array with delimiter using string.Join? - c #How to program the bootloader ..? Want a USB stick with Windows 7, XP, Vista and possibly 98 SE to be used for installation - windows-7How does iOS solve memory fragmentation? - ios4Logging Stack Information - c #MySQL INSERT only if the row does not exist, otherwise select a duplicate row - mysqlSQL selects row pattern - sql-server-2008How to work with strings in ARM? - cCreating Bonjour Services for Finder - pythonCompiling with the Flex4 SDK - flexdefine the parameter $ right with a variable in R - rAll Articles