简单例子,应能满足要求;
程序一激活就可涂鸦,按 Esc 就恢复屏幕, 按 C 改画笔色彩, 按 + /- 改线宽
按 Q 结束程序。
至于托盘图标,自己解决吧。
unit ScreenModi;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, AppEvnts,math;
type
TForm1 = class(TForm) // borderStyle设置为bsNone;
Image1: TImage; //Align 设置为Alclient;
ApplicationEvents1: TApplicationEvents;
ColorDialog1: TColorDialog;
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
procedure ApplicationEvents1Activate(Sender: TObject);
procedure ApplicationEvents1Deactivate(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
public
end;
var
Form1: TForm1;
ISDown:Boolean;
CurrentColor:TColor;
CurrentWidth:Integer;
implementation
{$R *.DFM}
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
IF Key=Chr(27) then //Esc 隐藏
Begin
width:=0;
height:=0;
End;
IF Uppercase(Key)='Q' then // Q 键退出
Close;
IF Uppercase(Key)='C' then // C 键改色
IF ColorDialog1.Execute then
CurrentColor:=ColorDialog1.Color;
IF (Key='+') or (Key='=') //加减 笔宽
then
Inc(CurrentWidth);
IF (Key='-') or (Key='_')
then
Dec(CurrentWidth);
CurrentWidth:=Max(1,CurrentWidth);
End;
procedure TForm1.FormCreate(Sender: TObject);
begin
left:=0; top:=0; width:=0; height:=0;
CurrentColor:=Clred;
CurrentWidth:=3;
End;
procedure TForm1.ApplicationEvents1Activate(Sender: TObject);
Var Adc:HDC;
ACanvas:Tcanvas;
X:Tbitmap;
begin //抓屏幕到Image
X:=Tbitmap.Create;
X.width:=Screen.Width;
X.height:=Screen.height;
ADC:=getDC(0);
Acanvas:=TCanvas.Create;
Acanvas.Handle:=Adc;
X.Canvas.CopyRect(X.canvas.Cliprect,Acanvas,X.canvas.Cliprect);
width:=Screen.Width;
height:=Screen.Height;
Image1.Picture.Bitmap.assign(X);
Image1.refresh;
X.Free;
Acanvas.Free;
End;
procedure TForm1.ApplicationEvents1Deactivate(Sender: TObject);
begin
left:=0;
top:=0;
width:=0;
height:=0;
ISDOwn:=False;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Begin
ISDown:=True; //开始手工绘制
With Image1.Picture.Bitmap.Canvas do
Begin
Pen.width:=CurrentWidth;
Pen.Color:=CurrentColor;
Moveto(X,Y);
Lineto(X,Y);
End;
End;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
IF ISdown then Image1.Picture.Bitmap.Canvas.Lineto(X,Y);
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ISDOwn:=False;
end;
End.