硬
硬木花椒
Unregistered / Unconfirmed
GUEST, unregistred user!
你是要屏幕上局部抓图吗?<br>部分代码提示:<br>unit partscreen;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> ExtCtrls;<br><br>type<br> TForm3 = class(TForm)<br> Timer1: TTimer;<br> Image1: TImage;<br> procedure Timer1Timer(Sender: TObject);<br> procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;<br> Shift: TShiftState; X, Y: Integer);<br> procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,<br> Y: Integer);<br> private<br> { Private declarations }<br> x1,x2,y1,y2,oldx,oldy,foldx,foldy:integer;<br> trace,flag:boolean;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form3: TForm3;<br><br>implementation<br>uses fullscreen;<br>{$R *.DFM}<br><br>procedure TForm3.Timer1Timer(Sender: TObject);<br>var<br> fullscreen:tbitmap;<br> fullscreencanvas:tcanvas;<br> dc:hdc;<br>begin<br> form3.timer1.Enabled :=false;<br>// 在部分抓取方法中保存了本程序的主界面<br> fullscreen:=tbitmap.Create; // create a bitmap to save picture<br> fullscreen.Width :=screen.Width;<br> fullscreen.Height :=screen.Height;<br> dc:=getdc(0);//get screen's dc<br> fullscreencanvas:=tcanvas.Create;//create screen's canvas<br> fullscreencanvas.Handle :=dc;<br> fullscreen.Canvas.CopyRect (rect(0,0,screen.width,screen.height),fullscreencanvas,rect(0,0,screen.width,screen.height));<br> fullscreencanvas.Free;<br> releasedc(0,dc);<br>//<br> form3.image1.Picture.Bitmap :=fullscreen;<br> form3.image1.Width :=fullscreen.Width;<br> form3.image1.Height :=fullscreen.Height;<br> fullscreen.Free;<br> form3.WindowState :=wsmaximized;<br> form3.show;<br> messagebeep(1);<br>//<br> form3.foldx:=-1;<br> form3.foldy:=-1;<br> form3.Image1.Canvas.Pen.Mode :=pmnot;<br> form3.Image1.Canvas.Pen.color:=clred;<br> form3.Image1.Canvas.brush.style:=bsclear;<br> flag:=true;<br><br>end;<br>procedure TForm3.Image1MouseDown(Sender: TObject; Button: TMouseButton;<br> Shift: TShiftState; X, Y: Integer);<br>var<br> wid,high:integer;<br> newbitmap:tbitmap;<br>begin<br> if trace=false then<br> begin<br> flag:=false;<br> with form3.Image1.Canvas do<br> begin<br> moveto(foldx,0);<br> lineto(foldx,screen.height);<br> moveto(0,foldy);<br> lineto(screen.width,foldy);<br> end;<br>//<br> x1:=x;<br> y1:=y;<br> oldx:=x;<br> oldy:=y;<br> trace:=true;<br> form3.Image1.Canvas.pen.mode:=pmnot;<br> form3.Image1.Canvas.Pen.color:=clblack;<br> form3.Image1.Canvas.brush.style:=bsclear;<br> end<br> else<br> begin<br> x2:=x;<br> y2:=y;<br> trace:=false;//cancel that rect<br> form3.Image1.canvas.Rectangle(x1,x2,oldx,oldy);<br> wid:=abs(x2-x1);<br> high:=abs(y2-y1);<br> form3.Image1.Width :=wid;<br> form3.image1.Height :=high;<br> newbitmap:=tbitmap.create;//new a bitmap<br> newbitmap.width:=wid;<br> newbitmap.height:=high;<br> newbitmap.Canvas.CopyRect(rect(0,0,wid,high),form3.Image1.Canvas,rect(x1,y1,x2,y2));//copy to bitmap<br> form2.Image1.Picture.Bitmap :=newbitmap;//assign to form1's image1<br> newbitmap.free;//free this bitmap<br> form2.show;<br> form3.Hide;<br> end;<br><br>end;<br><br>procedure TForm3.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,<br> Y: Integer);<br> begin<br> if trace=true then<br> begin<br> with form3.image1.canvas do<br> begin<br> rectangle(x1,y1,oldx,oldy);<br> rectangle(x1,y1,x,y);<br> oldx:=x;<br> oldy:=y;<br> end;<br> end<br> else if flag=true then<br> begin<br> with form3.image1.canvas do<br> begin<br> moveto(foldx,0);<br> lineto(foldx,screen.height);<br> moveto(0,foldy);<br> lineto(screen.width,foldy);<br> moveto(x,0);<br> lineto(x,screen.height);<br> moveto(0,y);<br> lineto(screen.width,y);<br> foldx:=x;<br> foldy:=y;<br> end;<br> end;<br>end;<br> <br>end.