To save a colour press space bar.
But please make sure that the little window is active if you do this.
By save I mean that the results are shown on a console where they can be copied.
Code: Select all
#include "crt.bi"
Type screenpoint
As Integer x,y
End Type
Extern "windows" Lib "user32"
Declare Function GetDC Alias "GetDC" (Byval As Any Ptr) As Any Ptr
Declare Function PopBeep Alias "MessageBeep" (Byval As Integer) As Integer
End Extern
Extern "windows" Lib "gdi32"
Declare Function _point Alias "GetPixel"(Byval As Any Ptr,Byval As Integer,Byval As Integer) As Uinteger
End Extern
Declare Function _getmouse Alias "GetCursorPos" (Byval As Any Pointer) As Integer
Declare Function NoConsole Alias "FreeConsole" () As Integer
declare function ShowConsole alias "AllocConsole" as integer
Dim Shared As Integer xres,yres
'=============================
function HTML(v as uinteger) as string
dim as string hx=hex(v)
hx=string(6-len(hx),"0")+hx
swap hx[0],hx[4]
swap hx[1],hx[5]
return hx
end function
'=======================================
Dim As Any Ptr MyScreen = GetDC(0)
Dim As Uinteger v
Screenres 200,200,32,,&h20 or &h40
Windowtitle "Colour finder"
Screeninfo xres,yres
width xres\8,yres\16
NoConsole
Dim As Ubyte r,g,b
Color ,RGB (236,233,216)
Dim As screenpoint m
dim as string key,s=" " +chr(10),msg
dim as integer x,y
Do
key=inkey
if key=" " then
popbeep(0)
var bb=string(3-len(str(b)),"0")+str(b),rr=string(3-len(str(r)),"0")+str(r),gg=string(3-len(str(g)),"0")+str(g)
var sp=string(6-len(hex(v))," ")
s+= "RGB (" & bb &"," & gg &"," & rr &")"+ " HEX &h"+hex(v)+sp+" HTML #"+HTML(v) +chr(10)
end if
_getmouse @m
screencontrol 0,x,y
if m.x>x and m.x<x+xres and m.y>y and m.y<y+yres then msg="<space> to save a colour" else msg=""
Screenlock
Cls
Locate 1,1
Color 0
print "X,Y ";str(m.x);",";str(m.y)
'print
Print "Red ";b
Print "Green ";g
Print "Blue ";r
print
locate 10,1
print "HEX &h";hex(v)
draw string(0,180),msg,rgb(0,0,0)
print "HTML #";HTML(v)
Line(100-30,100-30)-(100+30,100+30),Rgb(b,g,r),bf
Line(100-30,100-30)-(100+30,100+30),Rgb(0,0,0),b
v=_point(MyScreen,m.x,m.y)
r= Cptr(Ubyte Ptr,@v)[2] 'Or just use the standard r,g,b extract method
g= Cptr(Ubyte Ptr,@v)[1] 'but this method is a tad faster
b= Cptr(Ubyte Ptr,@v)[0]
Screenunlock
Sleep 1,1
Loop Until key=Chr(255,107) or key=chr(27)
if s<>" " +chr(10) then
screen 0
showconsole
puts(s)
sleep
end if