如何用API在桌面上画方框?(50分)

你是要屏幕上局部抓图吗?<br>部分代码提示:<br>unit partscreen;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; ExtCtrls;<br><br>type<br>&nbsp; TForm3 = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; Image1: TImage;<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; &nbsp; procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; &nbsp; &nbsp; Shift: TShiftState; X, Y: Integer);<br>&nbsp; &nbsp; procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,<br>&nbsp; &nbsp; &nbsp; Y: Integer);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; x1,x2,y1,y2,oldx,oldy,foldx,foldy:integer;<br>&nbsp; &nbsp; trace,flag:boolean;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form3: TForm3;<br><br>implementation<br>uses fullscreen;<br>{$R *.DFM}<br><br>procedure TForm3.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; fullscreen:tbitmap;<br>&nbsp; fullscreencanvas:tcanvas;<br>&nbsp; dc:hdc;<br>begin<br>&nbsp; form3.timer1.Enabled :=false;<br>// 在部分抓取方法中保存了本程序的主界面<br>&nbsp; fullscreen:=tbitmap.Create; // create a bitmap to save picture<br>&nbsp; fullscreen.Width :=screen.Width;<br>&nbsp; fullscreen.Height :=screen.Height;<br>&nbsp; dc:=getdc(0);//get screen's dc<br>&nbsp; fullscreencanvas:=tcanvas.Create;//create screen's canvas<br>&nbsp; fullscreencanvas.Handle :=dc;<br>&nbsp; fullscreen.Canvas.CopyRect (rect(0,0,screen.width,screen.height),fullscreencanvas,rect(0,0,screen.width,screen.height));<br>&nbsp; fullscreencanvas.Free;<br>&nbsp; releasedc(0,dc);<br>//<br>&nbsp; form3.image1.Picture.Bitmap :=fullscreen;<br>&nbsp; form3.image1.Width :=fullscreen.Width;<br>&nbsp; form3.image1.Height :=fullscreen.Height;<br>&nbsp; fullscreen.Free;<br>&nbsp; form3.WindowState :=wsmaximized;<br>&nbsp; form3.show;<br>&nbsp; messagebeep(1);<br>//<br>&nbsp; form3.foldx:=-1;<br>&nbsp; form3.foldy:=-1;<br>&nbsp; form3.Image1.Canvas.Pen.Mode :=pmnot;<br>&nbsp; form3.Image1.Canvas.Pen.color:=clred;<br>&nbsp; form3.Image1.Canvas.brush.style:=bsclear;<br>&nbsp; flag:=true;<br><br>end;<br>procedure TForm3.Image1MouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; Shift: TShiftState; X, Y: Integer);<br>var<br>&nbsp; wid,high:integer;<br>&nbsp; newbitmap:tbitmap;<br>begin<br>&nbsp; if trace=false then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; flag:=false;<br>&nbsp; &nbsp; &nbsp; with form3.Image1.Canvas do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveto(foldx,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lineto(foldx,screen.height);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveto(0,foldy);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lineto(screen.width,foldy);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>//<br>&nbsp; &nbsp; &nbsp; x1:=x;<br>&nbsp; &nbsp; &nbsp; y1:=y;<br>&nbsp; &nbsp; &nbsp; oldx:=x;<br>&nbsp; &nbsp; &nbsp; oldy:=y;<br>&nbsp; &nbsp; &nbsp; trace:=true;<br>&nbsp; &nbsp; &nbsp; form3.Image1.Canvas.pen.mode:=pmnot;<br>&nbsp; &nbsp; &nbsp; form3.Image1.Canvas.Pen.color:=clblack;<br>&nbsp; &nbsp; &nbsp; form3.Image1.Canvas.brush.style:=bsclear;<br>&nbsp; &nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; x2:=x;<br>&nbsp; &nbsp; &nbsp; y2:=y;<br>&nbsp; &nbsp; &nbsp; trace:=false;//cancel that rect<br>&nbsp; &nbsp; &nbsp; form3.Image1.canvas.Rectangle(x1,x2,oldx,oldy);<br>&nbsp; &nbsp; &nbsp; wid:=abs(x2-x1);<br>&nbsp; &nbsp; &nbsp; high:=abs(y2-y1);<br>&nbsp; &nbsp; &nbsp; form3.Image1.Width :=wid;<br>&nbsp; &nbsp; &nbsp; form3.image1.Height :=high;<br>&nbsp; &nbsp; &nbsp; newbitmap:=tbitmap.create;//new a bitmap<br>&nbsp; &nbsp; &nbsp; newbitmap.width:=wid;<br>&nbsp; &nbsp; &nbsp; newbitmap.height:=high;<br>&nbsp; &nbsp; &nbsp; newbitmap.Canvas.CopyRect(rect(0,0,wid,high),form3.Image1.Canvas,rect(x1,y1,x2,y2));//copy to bitmap<br>&nbsp; &nbsp; &nbsp; form2.Image1.Picture.Bitmap :=newbitmap;//assign to form1's image1<br>&nbsp; &nbsp; &nbsp; newbitmap.free;//free this bitmap<br>&nbsp; &nbsp; &nbsp; form2.show;<br>&nbsp; &nbsp; &nbsp; form3.Hide;<br>&nbsp; &nbsp; end;<br><br>end;<br><br>procedure TForm3.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,<br>&nbsp; Y: Integer);<br>&nbsp; begin<br>&nbsp; if trace=true then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; with form3.image1.canvas do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rectangle(x1,y1,oldx,oldy);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rectangle(x1,y1,x,y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oldx:=x;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oldy:=y;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end<br>&nbsp; else if flag=true then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; with form3.image1.canvas do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveto(foldx,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lineto(foldx,screen.height);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveto(0,foldy);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lineto(screen.width,foldy);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveto(x,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lineto(x,screen.height);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveto(0,y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lineto(screen.width,y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foldx:=x;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foldy:=y;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>end;<br>&nbsp;<br>end.
 
................
 
E-mail:zhenghui8101@21cn.com<br>把代码发过来
 
to nzfsoft:如果代码通过就结贴吧<br>to doll_paul:这是一个抓屏的函数,我曾经做过一个类似delphi鼠标移动的例子,<br>当采用image控件引入不同的图片作为背景时控件边上的八个点还要保持为黑点,就是<br>采用抓屏再调出的方法解决的。我想你的要求在于解决方案,而不是在于是否用api解决<br>你应该到图形图象分类上去提问。<br>redrawwindow如何取得指定区域的句柄,我要查一下。<br>Procedure TForm1.SaveScreen(FramePoint:TPoint;pWidth:integer;pHeight:integer;filename:string);<br>var<br>&nbsp; TempPoint:TPoint;<br>&nbsp; Dc: HDC;<br>&nbsp; bmp:TBitMap;<br>begin<br>&nbsp; TempPoint.x:=FramePoint.x-2; &nbsp;//源设备场景<br>&nbsp; TempPoint.y:=FramePoint.y-2;<br>&nbsp; Bmp:= TBitMap.Create; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //创建,设置其大小,目标设备场景<br>&nbsp; Dc:=GetDc(0);<br>&nbsp; bmp.Width:=pWidth; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//宽度<br>&nbsp; bmp.Height:=pHeight; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//长度<br>&nbsp; BitBlt(Bmp.Canvas.Handle,0,0,100,100,Dc,TempPoint.x,TempPoint.y,SRCCOPY);<br>&nbsp; bmp.SaveToFile(filename);<br>&nbsp; ReleaseDc(0,Dc);<br>&nbsp; bmp.free; &nbsp; &nbsp; &nbsp; &nbsp; //释放DC资源<br>end;
 
to zhenghui:现在还不能结分啊,问题完了,我会告诉nzfsoft来结分的!<br><br>另外,我不是要抓屏,我只是要在桌面创任意地方画方框,就像SPY++一样,但我画第二个时<br>原来的方框并不是清楚!<br><br>用redrawwindow虽然可以,但只能全部涮新,闪烁很历害。局部涮新,我成功不了!<br><br>谢谢~<br><br>另外,我发信给你要QQ了,希望可以给我!
 
to doll_paul:<br>&nbsp; 对不起!我没有QQ,无法申请!<br>&nbsp; 十分抱歉!如果你想交流编程经验,就留下e-mail吧
 
我是个网络工程人员,从事系统集成和unix平台下的编程。对windows编程也是新手。<br>因为最近我手上还有未完的项目,所以你的问题不能及时回答,请原谅!<br>Spy++是什么?可以发给我看一下吗?<br>另外可以把你的代码也发过来吧!不一定非的用redrawwindow,或许有更好的实现方法
 
to zhenghui,看来你公司管的比较。。。。那MSN能不能用呀?总之,能否找个即时通讯<br>的工具?这样,我们联系比较方便啦~<br><br>另外,我说的SPY,是VC++里的窗体调试程序!<br><br>至于我的代码,在家呢,现在在公司,明天我发给你~ :)
 
我的操作系统是win98,没有msn.<br>让你见笑了,连vc都不懂。我明天去装个icq吧!<br>腾讯的oicq最近无法申请
 
我的老大啊,98下可以装MSN的啦!!!!
 
http://www.onlinedown.net/msnmessenger.htm,自己下吧~
 
0..........
 
对于聊天这方面,我实在很菜
 
下班了,晚上要上课,不能在线上!bye!
 
OK,收到,我也刚下课回来,明天见了,呵呵~[:D]
 
已经注册成功,名称摆渡人!<br>
 
老大,查不到你~<br><br>你加我吧:doll_paul@msn.com[8D][8D][8D]
 
没有联机
 
...........
 
这个问题代朋友问的.结了吧.
 
顶部