var
arect:trect;
acanvas:tcanvas;
dc:hdc;
procedure initmdc;{先初始化}
begin
dc:=getdc(0);
arect:=rect(0,0,0,0);
acanvas:=tcanvas.create;
acanvas.handle:=dc;
end;
procedure directorymdc;{关闭时释放}
begin
releasedc(0,dc);
acanvas.free;
end;
proceudre mdcout;
var
str:string;
sw,sh:integer;
begin
{这里应该先调用函数刷新上一次输出区域}
//InvalidateRect(0,@arect,true); //这句有问题,0应该是整个桌面,但是如果第一个参数给的是0,就会无视后面的arect范围而刷新整个桌面造成闪烁....
str:='x:'+inttostr(mouse.cursorpos.x)+' y:'+inttostr(mouse.cursorpos.y);
sw:=acanvas.textwidth(str);
sh:=acanvas.textheight(str);
arect.left:=mouse.cursorpos.x-sw div 2 -30;
arect.top:=mouse.cursorpos.y-sh div 2 -30;
arect.right:=mouse.cursorpos.x+sw div 2 +30;
arect.bottom:=mouse.cursorpos.y+sh div 2 +30;
{画十字}
acanvas.pen.width=3;
acanvas.pen.color=clblue;
acanvas.moveto(arect.left,mouse.cursorpos.y);
acanvas.lineto(mouse.cursorpos.x-sw div 2,mouse.cursorpos.y);
acanvas.moveto(mouse.cursorpos.x+sw div 2,mouse.cursorpos.y);
acanvas.lineto(arect.right,mouse.cursorpos.y);
acanvas.moveto(mouse.cursorpos.x,arect.top);
acanvas.lineto(mouse.cursorpos.x,mouse.cursorpos.y-sh div 2);
acanvas.moveto(mouse.cursorpos.x,mouse.cursorpos.y+sh div 2);
acanvas.lineto(mouse.cursorpos.x,arect.bottom);
{输出文字}
acanvas.brush:=bsClear;
acanvas.font.color=clred;
acanvas.textout(mouse.cursorpos.x-sw div 2,mouse.cursorpos.y-sh div 2,str);
end;