频道分类

delphi 屏幕取色

作者:admin 来源: 日期:2020/3/9 9:43:08 人气: 标签:

 
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Menus;



type
  TForm1 = class(TForm)
    Image1: TImage;
    Timer1: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    TrayIcon1: TTrayIcon;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure hotykey(var msg:TMessage); message WM_HOTKEY;
  end;


var
  Form1: TForm1;
  HotKey:Integer;
  i:integer;

implementation

{$R *.dfm}

procedure TForm1.hotykey(var msg:TMessage);   //热键响应事件
begin
if (msg.LParamLo=0) and (msg.LParamHi=113) then
begin
if i=0 then
  begin
    Timer1.Enabled:=False;
    i:=1;
  end
  else
  begin
    Timer1.Enabled:=True;
    i:=0;
  end;
end; 
end;



procedure TForm1.Timer1Timer(Sender: TObject);
var
dc: HDC;
zhuo: TCanvas;
pt: tpoint;
x1,y1:Integer ;
i,j:integer;
X,Y,b,n,k,l:longint;
  t,clr:tcolor;
  r:byte;
  g:byte;
  f:byte;
  DesktopDC: HDC;
  er:string;
begin
GetCursorPos(pt); //得到鼠标的坐标
x1:=image1.Width ;
y1:=image1.Height ;

DesktopDC :=GetWindowDC(GetDesktopWindow);
t:=GetPixel(DesktopDC,pt.X,pt.Y);
r:=getrvalue(t);
g:=getgvalue(t);
f:=getbvalue(t);
label1.Caption:='红:'+inttostr(r)+'   ';
label2.Caption:='绿:'+inttostr(g)+'   ';
label3.Caption:='蓝:'+inttostr(f)+'   ';
er:=IntToHex(TColor(RGB(f,g,r)),8);
er:=copy(er,3,6);
label4.Caption:='#'+er;


dc := Getdc(0); //得到桌面的DC
zhuo := TCanvas.Create;

zhuo.Handle := dc; //建一个屏幕的对像
image1.Canvas.copyrect //开始拷屏
(rect(0, 0,image1.Width ,image1.Height ),   //图像控件左边=0,右边=0,
    zhuo,                                     //   图像显示控件的全部
    rect(pt.X - 20, pt.Y - 20,                 //要放大的倍 就改变图像控件的大小
     pt.X + 20, pt.Y + 20));

zhuo.Free;
ReleaseDC(0, dc);
X:=129;       //获取屏幕最大X
Y:=121;       //获取屏幕最大Y
b:=X div 2;
n:=Y div 2;
image1.Canvas.Pen.Color:=clblack;
image1.Canvas.Pen.Width :=0;
image1.Canvas.MoveTo(b-10,n);      {直线起点}
image1.Canvas.LineTo(b+10,n);    {直线终点}
image1.Canvas.MoveTo(b,n-10);      {直线起点}
image1.Canvas.LineTo(b,n+10);

k:=GetSystemMetrics(SM_CXSCREEN);
l:=GetSystemMetrics(SM_CYSCREEN);

if (pt.X>k-300)and(pt.X<k)  then
begin
end
else
begin
Form1.Left:=pt.X+100;
end;

if (pt.Y>l-300)and(pt.Y<l)  then
begin
end
else
begin
Form1.Top:=pt.Y+100;
end;

if (pt.X>k-300)and(pt.X<k)  then
begin
Form1.Left:=pt.X-200;
end;
if (pt.Y>l-300)and(pt.Y<l)  then
begin
Form1.Top:=pt.Y-200;
end;


releasedc(0,dc);





end;






procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0;

TransparentColor:=True;
TransparentColorValue:=25;
Color:=Form1.TransparentColorValue;

HotKey:=GlobalAddAtom('HotKey');   //全局热键ID
RegisterHotKey(handle,HotKey,0,113);   //注册全局热键
end;

procedure TForm1.N1Click(Sender: TObject);
begin
Form1.Close;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(handle,HotKey);
end;

end.

上一篇:delphi 保存HotKey1.HotKey值下一篇:没有资料