Einzelnen Beitrag anzeigen

Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#10

Re: Screenshot, ohne das eigene Fenster drauf ist.

  Alt 24. Apr 2007, 10:09
Zitat von _frank_:
warum so kompliziert?

Delphi-Quellcode:
formx.hide;
makescreenshot;
formx.show;
hat bei mir damals wunderbar funktioniert

Gruß Frank
Ist recht unsicher, das Fenster (die Form) versteckt ja nicht Delphi sondern Windows.
Ist das System ausgelastet oder hat noch keine Lust dazu kann es passieren das der
Screenshot schneller aufgerufen wird als die gesendete Message vom Programm an Win. das
Fenster zu "verstecken".

Am besten ist wohl in diesem Falle vorhrer zu Prüfen ob das Fenster sichtbar bzw. nicht sichtbar ist.

Code:
procedure FormXYZ.
begin
  FormX.Hide;
  while IsWindowVisible(Self.Handle) {und /oder Timelimit erreicht} do
    Application.ProcessMessage;
  MakeScreenShot;
  FormX.Show;
end;
Mit einer Windowsregion schaut das ungf. so aus:

Delphi-Quellcode:
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { Private-Deklarationen }
    bmp: TBitmap;
    procedure WMNCHitTest(var aMessage: TWMNCHitTest); message WM_NCHITTEST;
    procedure WMWindowPosChanging(var aMessage: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
    procedure WMEraseBkgnd(var aMessage: TWMEraseBkgnd); message WM_ERASEBKGND;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

var
  Rgn : HRGN;

function CreateRgnFromRect(ARect: TRect): HRGN;
begin
  Result := CreateRectRgn(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  bmp := TBitmap.Create;
  bmp.PixelFormat := pf24Bit;
  bmp.Width := Self.ClientWidth;
  bmp.Height := Self.ClientHeight;

  Rgn := CreateRgnFromRect(Self.ClientRect);
  SetWindowRgn(Handle, Rgn, TRUE);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  bmp.Free;
end;

procedure TForm1.WMNCHitTest(var aMessage: TWMNCHitTest);
var
  p : tpoint;
begin
  inherited;

  p.x := aMessage.XPos;
  p.y := aMessage.YPos;
  p := screenToClient(p);

  if PtInRect(Self.Clientrect, p) then
   aMessage.Result := HTCAPTION;
end;

procedure TForm1.WMWindowPosChanging(var aMessage: TWMWindowPosChanging);
var
  ScrDC: HDC;
  p: TPoint;
begin
  inherited;

  if isWindowVisible(Self.Handle) then
  begin

  p.x := aMessage.WindowPos.x;
  p.y := aMessage.WindowPos.y;

  bmp.Canvas.Brush.Style := bsSolid;
  bmp.Canvas.Pen.Color := clGreen;
  bmp.Canvas.FillRect(Self.Clientrect);

  // Screen to Bitmap
   ScrDC := GetDC(0);
    BitBlt(
        bmp.Canvas.Handle,
        0,
        0,
        bmp.Width,
        bmp.Height,
        ScrDC,
        p.x,
        p.y,
        SRCCOPY
      );
    ReleaseDC(0, ScrDC);

    Self.Paint;
  end;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  if isWindowVisible(Self.Handle) and Assigned(bmp) then
    Self.Canvas.Draw(0,0, bmp);
end;

procedure TForm1.WMEraseBkgnd(var aMessage: TWMEraseBkgnd);
begin
  aMessage.Result := 0;
end;

end.
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat