Recent

Author Topic: Desktop Colour Finder.  (Read 178 times)

BobDog

  • Jr. Member
  • **
  • Posts: 68
Desktop Colour Finder.
« on: October 28, 2020, 07:47:47 pm »
A simple console tool.
Code: Pascal  [Select][+][-]
  1. program finder;
  2.  
  3. uses windows,crt,sysutils;
  4.    const
  5.     DC_BRUSH=18;
  6.     const
  7.     DC_PEN=19;
  8.  
  9. type
  10. colour =packed record
  11. case integer of
  12. 0:(r,g,b:byte);
  13. 1:(c:longword);
  14. end;
  15.  
  16.  function Printf(mask : pchar):integer; cdecl; varargs; external 'msvcrt.dll' name 'printf';
  17.  function system(s:pchar):integer ; cdecl external 'msvcrt.dll' name 'system';
  18.  function SetDCBrushColor(p:hdc;colour:COLORREF): COLORREF; stdcall external 'gdi32.dll' name 'SetDCBrushColor';
  19.  function SetDCPenColor(p:hdc;colour:COLORREF): COLORREF; stdcall external 'gdi32.dll' name 'SetDCPenColor';
  20.  function SetWindowTheme(p: hwnd; p1: PChar; p2: PChar): integer; external 'UxTheme.dll' Name 'SetWindowTheme';
  21.  
  22.  procedure hidecursor();
  23.  var
  24.     consoleHandle:handle;
  25.      info:CONSOLE_CURSOR_INFO ;
  26.      begin
  27.      consolehandle := GetStdHandle(STD_OUTPUT_HANDLE);
  28.      info.dwSize := 100;
  29.      info.bVisible := FALSE ;
  30.      SetConsoleCursorInfo(consoleHandle, @info);
  31.      End;
  32.  
  33. Var
  34. p:hwnd;
  35. h,wh:hdc;
  36. pt:point;
  37. clr:colour;
  38. r:integer=50;
  39. s:pchar;
  40. begin
  41.     p := GetConsoleWindow();
  42.     setwindowpos(p, HWND_TOPMOST, 100, 100, 200, 280, SWP_SHOWWINDOW);
  43.     SetWindowTheme(p,' ',' ');
  44.     system('title [MOVE]');
  45.   SetWindowLong(p,GWL_STYLE, GetWindowLong(p, GWL_STYLE) and not(WS_MAXIMIZEBOX) and not( WS_SIZEBOX));
  46.     hidecursor();
  47.     h:=GetDC(0);
  48.     wh:=GetDC(p);
  49.     SelectObject(wh,GetStockObject(DC_BRUSH));
  50.     SelectObject(wh,GetStockObject(DC_PEN));
  51.     while p<>1 do
  52.     begin
  53.     getcursorpos(@pt);
  54.     clr.c:=getpixel(h,pt.x,pt.y);
  55.     ShowScrollBar(p, SB_BOTH, FALSE);
  56.     SetDCBrushColor(wh,clr.c);
  57.     SetDCPenColor(wh,clr.c);
  58.  ellipse(wh,trunc(95-r),trunc(70-r),trunc(95+r),trunc(70+r));
  59.  
  60.   gotoxy(3,10);
  61.   printf('Red   %s','   ');
  62.   gotoxy(3,10);
  63.   printf('Red   %d',clr.r);
  64.  
  65.   gotoxy(3,11);
  66.   printf('Green %s','   ');
  67.   gotoxy(3,11);
  68.   printf('Green %d',clr.g);
  69.  
  70.   gotoxy(3,12);
  71.   printf('Blue  %s','   ');
  72.   gotoxy(3,12);
  73.   printf('Blue  %d',clr.b);
  74.  
  75.   gotoxy(3,13);
  76.   printf('HEX   %s','          ');
  77.   gotoxy(3,13);
  78.   s:=pchar(IntToHex(clr.c,8));
  79.   printf('HEX  %s',' $');
  80.   printf('%s',s);
  81.  
  82.   gotoxy(3,14);
  83.   printf('RAW   %s','          ');
  84.   gotoxy(3,14);
  85.   printf('RAW   %d',clr.c);
  86.  
  87.   gotoxy(3,15);
  88.   printf('X,Y   %s','             ');
  89.   gotoxy(3,15);
  90.   printf('X,Y   %d ,%s %d',pt.x,'',pt.y);
  91.     sleep(20);
  92.     end;
  93.  
  94. end.
  95.  

Tested 64 bit fpc Win 10.
Auld Lang Syne
« Last Edit: October 29, 2020, 01:12:00 pm by BobDog »

 

TinyPortal © 2005-2018