delphi - Draw/overlay a rectangle box on top of application and capture mouse XY -


i have cad application trying build plugin , need able select lines , arcs. cannot directly application. in code want start drawing windowing rectangle free hand mouse. through api can determine lines/arcs enclosed in rectangle drawn.

the question is, how can draw rectangle mouse on top of application? left click start upper left corner, drag resize, , releasing left click end rectangle? there's not forms involved either, don't know if can use picturebox/tcanvas or what. me, windowing screen capture draw rectangle on part of screen want save.

i used xor draw rectangle proposed fduenas , works quite well, not work smoothly on windows vista , 7. rectangle may partially erased if draw on changing areas (and pieces of rectangle remain if erase afterwards).

instead use rectangular window rectangular hole in it. have reposition window. can create , show in mousedown, reposition in mousemove , destroy in mouseup.

set borderstyle of tdragrectangleform bsnone.

unit frmdragrectangle;  // tdragrectangleform rectangular window rectangular hole. // dotted border visible.  interface  uses   windows, forms, graphics, classes;  type   tdragrectangleform = class( tform )     procedure formresize( sender : tobject );   public     procedure show;   end;  implementation  {$r *.dfm}  procedure tdragrectangleform.show; begin   // show window without stealing focus window:   showwindow( handle , sw_shownoactivate );   visible := true; end;  procedure tdragrectangleform.formresize( sender : tobject ); const   nborderwidth = 1; var   hrgnrect1 , hrgnrect2 : hrgn; begin   // make rectangular hole in window:   hrgnrect1 := createrectrgn( 0 , 0 , width , height );   hrgnrect2 := createrectrgn( nborderwidth , nborderwidth , width - nborderwidth , height - nborderwidth );    combinergn( hrgnrect1 , hrgnrect1 , hrgnrect2 , rgn_diff );   setwindowrgn( handle , hrgnrect1 , true );   deleteobject( hrgnrect2 );    canvas.pen.style := psdot;   canvas.pen.color := clwhite;   canvas.brush.color := clblack;   canvas.rectangle( 0 , 0 , width , height ); end;  end. 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -