delphi 屏幕取色


本文整理自网络,侵删。

 
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 datasanp的控制老大-dsserver

Delphi屏蔽webbrowser页面中传出来的声音

Delphi 几个dataset数据导出到xml word excel txt html的函数

Delphi 让窗体自适应屏幕显示

Delphi real控件 rm格式的播放器

Delphi 取得当前运行窗口的标题

Delphi unigui 获取当前ip

Delphi 实现给字加边界代码

Delphi 如何将颜色值转换为html格式?

Delphi android / ios应用程序中使用tgeocoder类进行反向地理编码(从位置信息中获取地址)

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...