Board index » delphi » Over my head, again

Over my head, again

Greetings all;

I have a need to capture part of the screen.  I can capture the whole
screen, I can capture part of it (by loading the screen coordinates and
BitBlt(bm.Canvas.Handle, 0, 0, Width, Height, Dc, x, y, SRCCOPY);)  Now I
would like to press a button minimize the app (this I can do) then say,
like in PaintShopPro, right click the mouse and begin the capture.  mouse
down to start the drag. drag to the endpoint, and on upmouse, release the
image back into the program.  I do not know how to do this outside the
bounds of the form.  If some kind soul could point me in the right
direction, I certainly would appreciate the help.  I am sure there is
examples out there, but I don't even know what to search for... ("Thinking
outside the box" was a waste of time and electrons)

anyway, thanks for your time and Merry Christmas to all

Bill

 

Re:Over my head, again


Quote
> I have a need to capture part of the screen.  I can capture the whole
> screen, I can capture part of it (by loading the screen coordinates and
> BitBlt(bm.Canvas.Handle, 0, 0, Width, Height, Dc, x, y, SRCCOPY);)  Now I
> would like to press a button minimize the app (this I can do) then say,
> like in PaintShopPro, right click the mouse and begin the capture.  mouse
> down to start the drag. drag to the endpoint, and on upmouse, release the
> image back into the program.  I do not know how to do this outside the
> bounds of the form.  If some kind soul could point me in the right
> direction, I certainly would appreciate the help.  I am sure there is
> examples out there, but I don't even know what to search for... ("Thinking
> outside the box" was a waste of time and electrons)

You could just make a copy of the whole screen as soon as the capture is
called, stick the bitmap on a form and write code to create a lassoo box
around it within the form. Then once this is complete, crop the image and do
what you want with it...

Nick

Re:Over my head, again


Hi Nick;

Quote
> You could just make a copy of the whole screen as soon as the capture is
> called, stick the bitmap on a form and write code to create a lassoo box
> around it within the form. Then once this is complete, crop the image and
do
> what you want with it...

> Nick

actually, what I am currently doing is close to that.  ( manually plug in
the points.  I can resize the form and it resizes the area captured)  but I
was hoping for a more elegant interface.....

thanks for the response

Bill

Re:Over my head, again


[ed.note: I sent this reply out two hours ago, it did not show up in my
viewer, if it shows up as a double post, my sincere apology]

Hi Nick;

Quote
> You could just make a copy of the whole screen as soon as the capture is
> called, stick the bitmap on a form and write code to create a lassoo box
> around it within the form. Then once this is complete, crop the image and
do
> what you want with it...

> Nick

actually, what I am currently doing is close to that.  ( manually plug in
the points.  I can resize the form and it resizes the area captured)  but I
was hoping for a more elegant interface.....

thanks for the response

Bill

Re:Over my head, again


Try Apprehend 2000... its a free VCL component that does what you are
looking for ... and more.  Compiles in Delphi 4, 5 and 6.

http://www.software.adirondack.ny.us

Bill Miller
Adirondack Software & Graphics

Quote
"Bill" <btalb...@fbtc.net> wrote in message news:3c235381$1_2@dnews...
> Greetings all;

> I have a need to capture part of the screen.  I can capture the whole
> screen, I can capture part of it (by loading the screen coordinates and
> BitBlt(bm.Canvas.Handle, 0, 0, Width, Height, Dc, x, y, SRCCOPY);)  Now I
> would like to press a button minimize the app (this I can do) then say,
> like in PaintShopPro, right click the mouse and begin the capture.  mouse
> down to start the drag. drag to the endpoint, and on upmouse, release the
> image back into the program.  I do not know how to do this outside the
> bounds of the form.  If some kind soul could point me in the right
> direction, I certainly would appreciate the help.  I am sure there is
> examples out there, but I don't even know what to search for... ("Thinking
> outside the box" was a waste of time and electrons)

> anyway, thanks for your time and Merry Christmas to all

> Bill

Re:Over my head, again


Quote
Bill wrote in message <3c235381$1_2@dnews>...
>bounds of the form.  If some kind soul could point me in the right
>direction, I certainly would appreciate the help.  I am sure there is
>examples out there, but I don't even know what to search for... ("Thinking
>outside the box" was a waste of time and electrons)

The way I did it was to create a new modal form of the size of the screen
containing a screenshot of the entire screen. What I do is the following:

1) user presses a button, which minimizes the main form
2) this prompts my program to set up a global keyboard hook
3) the user then enters the magic key combination (Ctrl-Shift-Q in my case)
4) this prompts the program to create a new modal form (and also to restore
itself)
5) the modal form contains a screenshot of the screen at the time the key
combo was pressed - the user doesn't notice the modal form
6) then the user draws a "lasso" rectangle (use mouse down, mouse move and
mouse up events, as well as the xor drawfocusrect function)
7) this prompts the program to copy that part of the canvas to a bitmap,
which then can be output to a file or to the clipboard. The global hook is
turned off.

Mark Q

Re:Over my head, again


One way can be to use DirectInput and then you are clear with windows focus
and message handling...

--
Liran Shahar
Com-N-Sense (www.com-n-sense.com)

Re:Over my head, again


Hi Bill,

You could also use the GetCapture and ReleaseCapture functions, which gives
you the abillity to recieve mouse events even though you are outside you
app. I used it for a menu class I wrote and it works fine. Here is an
example :

<-----Code begin---------
procedure TEPunktMenuControl.CaptureMouse;
begin
  ReleaseMouse;
  FCapture := GetCapture;
  SetCapture(Handle);
  FCaptured := True;
end;

procedure TEPunktMenuControl.ReleaseMouse;
begin
  if FCaptured then
  begin
    ReleaseCapture;
    if FCapture <> 0 then
    begin
      SetCapture(FCapture);
      FCapture := 0;
    end;
    FCaptured := False;
  end;
end;

<-----Code end---------

Regards
Michael Skovslund.

Quote
"Bill" <btalb...@fbtc.net> wrote in message news:3c235381$1_2@dnews...
> Greetings all;

> I have a need to capture part of the screen.  I can capture the whole
> screen, I can capture part of it (by loading the screen coordinates and
> BitBlt(bm.Canvas.Handle, 0, 0, Width, Height, Dc, x, y, SRCCOPY);)  Now I
> would like to press a button minimize the app (this I can do) then say,
> like in PaintShopPro, right click the mouse and begin the capture.  mouse
> down to start the drag. drag to the endpoint, and on upmouse, release the
> image back into the program.  I do not know how to do this outside the
> bounds of the form.  If some kind soul could point me in the right
> direction, I certainly would appreciate the help.  I am sure there is
> examples out there, but I don't even know what to search for... ("Thinking
> outside the box" was a waste of time and electrons)

> anyway, thanks for your time and Merry Christmas to all

> Bill

Re:Over my head, again


unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm2 = class(TForm)
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormPaint(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
        fDragging: Boolean;
 //   procedure WMEraseBkGnd( Var Msg: TWMEraseBkGnd );
 //   message WM_ERASEBKGND;
  public
    { Public declarations }
    fRect: TRect;
    fBmp: TBitmap;
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.DFM}
Var
p : TPoint;

procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  P := Point(x, y);
  if mbLeft = Button then
  begin
    fDragging := True;
    SetRect( fRect, X, Y, X, Y );
    Canvas.DrawFocusrect( fRect );
  end;
end;

procedure TForm2.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if fDragging then begin
    Canvas.DrawFocusrect( fRect );
    fRect.Right  := X;
    fRect.Bottom := Y;
    Canvas.DrawFocusrect( fRect );
  end;
end;

procedure TForm2.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if fDragging then begin
    Canvas.DrawFocusrect( fRect );
    fDragging := False;
  end;
  ModalResult := mrOK;
  Form1.TempBitmap.Width := X - P.X;
  Form1.TempBitmap.Height := Y - P.Y;
  Form1.MyBitmap.Width := Form1.TempBitmap.Width;
  Form1.MyBitmap.Height := Form1.TempBitmap.Height;
  /////////
//  Form1.MyBitmap.PixelFormat := pf8bit;
 // Form1.TempBitmap.PixelFormat := pf8bit;
  /////////
  Form1.TempBitmap.Canvas.CopyRect(Rect(0,0,X-P.X,Y-P.Y), fBmp.Canvas,
Rect(P.X,P.Y,X,Y));
  Form1.MyBitmap.Canvas.CopyRect(Rect(0,0,X-P.X,Y-P.Y), fBmp.Canvas,
Rect(P.X,P.Y,X,Y));
  Form1.Image1.Picture.Assign(Form1.TempBitmap);
  Form1.Image1.Canvas.Brush.Style := bsClear;
  Form1.Image1.Canvas.Pen.color := Clred;
  Form1.Image1.Canvas.Pen.Width := 2;
  Form1.Image1.Canvas.Pen.Style := psSolid;
  Form1.Margin;
  Form1.Visible := True;
  close;
end;

procedure TForm2.FormPaint(Sender: TObject);
begin
   Canvas.Draw( 0, 0, fBMP );
end;

{Procedure TForm2.WMEraseBkGnd( var Msg: TWMEraseBkGnd );
begin
 // Msg.Result := 1;
end; }

procedure TForm2.FormShow(Sender: TObject);
var
  aDC: HDC;
begin
  Form1.Gif := False;
  fBMP        := TBitmap.Create;
  fBMP.Width  := Screen.Width;
  fBMP.Height := Screen.Height;
  aDC         := GetDC( 0 );
  BitBlt( fBMP.Canvas.handle, 0, 0, Screen.Width, Screen.Height,
          aDC, 0, 0, srcCopy );
  ReleaseDC( 0, aDC );                            //?
  SetBounds( 0, 0, Screen.Width, Screen.Height ); //?
end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
fBmp.Free;
end;

end.

Other Threads