I
iCANK
Unregistered / Unconfirmed
GUEST, unregistred user!
是个屏幕取色的程序。另外,我想加入捕捉鼠标点击和鼠标移动,鼠标点击然后禁止<br>Timer1,把当前颜色copy到剪贴板,这段代码这么写?查过一些资料,说必须要用<br>mouse hook?但我不懂hook啊,而且,好像hook要在dll里调用,我不想再带一个dll,<br>就一个exe多好!:)有没有不用hook的方法就可以捕捉鼠标点击?捕捉鼠标移动是如果<br>鼠标没有在移动,就禁止Timer1,这样可能CPU占用率要小一些!<br><br>源程序:<br>unit ColorSpy_betaP;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> ExtCtrls, StdCtrls, Buttons, regions, VCLBase, EPLabels, epMorph;<br><br>type<br> TForm1 = class(TForm)<br> Label1: TLabel;<br> Timer1: TTimer;<br> Label2: TLabel;<br> Label3: TLabel;<br> DisColor: TShape;<br> epRegionForm1: TepRegionForm;<br> WndCaption: TepLabel;<br> CloseBtn: TepMorphButton;<br> Timer2: TTimer;<br> procedure Timer1Timer(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure CloseBtnClick(Sender: TObject);<br> procedure Timer2Timer(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br> MousePos: TPoint; //鼠标位置指针<br> MousePosX,MousePosY: string; //鼠标位置X轴,鼠标位置Y轴<br> MousePosColor,MousePosColorRed,MousePosColorGreen,MousePosColorBlue: longint; //鼠标位置颜色<br> MousePosColorRedH,MousePosColorGreenH,MousePosColorBlueH: string; //颜色16进制<br>begin<br> GetCursorPos(MousePos); //得到鼠标坐标<br> MousePosX := IntToStr(MousePos.x);<br> MousePosY := IntToStr(MousePos.y);<br> Label1.Caption := Format('鼠标位置:[ %s,%s ]',[MousePosX,MousePosY]);<br> MousePosColor := GetPixel(GetDC(0),MousePos.x,MousePos.y); //得到颜色。<br> MousePosColorRed := MousePosColor and $FF; //分离出红色<br> MousePosColorGreen := (MousePosColor and 65280) div 256; //分离出绿色<br> MousePosColorBlue := (MousePosColor and $FF0000) div 65536; //分离出蓝色<br> Label2.Caption := Format('RGB 颜色:[ %d,%d,%d ]',[MousePosColorRed,MousePosColorGreen,MousePosColorBlue]);<br> //方块显示颜色<br> DisColor.Brush.Color := RGB(MousePosColorRed,MousePosColorGreen,MousePosColorBlue);<br> //网页颜色16进制,不足8位的补齐8位。<br> MousePosColorRedH := Format('%x',[MousePosColorRed]);<br> if Length(MousePosColorRedH) = 1 then MousePosColorRedH := '0' + MousePosColorRedH;<br> MousePosColorGreenH := Format('%x',[MousePosColorGreen]);<br> if Length(MousePosColorGreenH) = 1 then MousePosColorGreenH := '0' + MousePosColorGreenH;<br> MousePosColorBlueH := Format('%x',[MousePosColorBlue]);<br> if Length(MousePosColorBlueH) = 1 then MousePosColorBlueH := '0' + MousePosColorBlueH;<br> Label3.Caption := Format('网页颜色:[ #%s%s%s ]',[MousePosColorRedH,MousePosColorGreenH,MousePosColorBlueH]);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);<br> Form1.Width := 178;<br> Form1.Height := 16;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> Application.MessageBox('这是icank的软件!!!:P','提醒!:-)',MB_ICONINFORMATION+MB_OK);<br>end;<br><br>procedure TForm1.CloseBtnClick(Sender: TObject);<br>begin<br> Close();<br>end;<br><br>procedure TForm1.Timer2Timer(Sender: TObject);<br>const<br> WndCreateSpeed = 10; //定义窗口打开和关闭时的步长<br>begin<br> Timer2.Enabled := True;<br> with Form1 do<br> Width := Width + WndCreateSpeed;<br> Height := Height + WndCreateSpeed;<br> Top := Screen.Height div 2 - Height div 2;<br> Left := Screen.Width div 2 - Width div 2;<br> if Height > 76 then Timer2.Enabled := False;<br>end;<br><br>end.<br>