Einzelnen Beitrag anzeigen

HolgerX

Registriert seit: 10. Apr 2006
Ort: Leverkusen
970 Beiträge
 
Delphi 6 Professional
 
#8

AW: Screenshot des aktiven Fenster genau wie Alt+Druck

  Alt 2. Jul 2016, 19:21
Teste doch mal:

Delphi-Quellcode:
Type
  TScreenShotSource = (sssActiveForm,sssActiveFormClient,sssPrimaryScreen,sssDesktopScreen);

procedure MakeScreenShot(const ATarget: TBitmap;ASource : TScreenShotSource;ASourceHandle : HWND = 0);
var
  tmpHandel : HWND;
  SourceDC: HDC;
  Rec: TRect;
begin
  tmpHandel := 0;
  SourceDC := 0;

  try
    ATarget.PixelFormat := pfDevice;
    if ASourceHandle > 0 then begin
      tmpHandel := ASourceHandle;
      case ASource of
        sssActiveFormClient : begin
                                SourceDC := GetDc(tmpHandel);
                                GetClientRect(tmpHandel,Rec);
                              end;
        else begin
          SourceDC := GetWindowDc(tmpHandel);
          GetWindowRect(tmpHandel,Rec);
        end;
      end;
    end else begin
      case ASource of
        sssActiveForm : begin
                                tmpHandel := GetForegroundWindow;
                                SourceDC := GetWindowDc(tmpHandel);
                                GetWindowRect(tmpHandel,Rec);
                              end;
        sssActiveFormClient : begin
                                tmpHandel := GetForegroundWindow;
                                SourceDC := GetDc(tmpHandel);
                                GetClientRect(tmpHandel,Rec);
                              end;
        sssPrimaryScreen : begin
                                tmpHandel := GetDesktopWindow;
                                SourceDC := GetDc(tmpHandel);
                                GetWindowRect(tmpHandel,Rec);
                              end;
        sssDesktopScreen : begin
                                tmpHandel := GetDesktopWindow;
                                SourceDC := GetDc(tmpHandel);
                                Rec.Left := 0;
                                Rec.Top := 0;
                                Rec.Right := Screen.DesktopWidth;
                                Rec.Bottom := Screen.DesktopHeight;
                              end;
        else exit;
      end;
    end;

    ATarget.Width := Rec.Right - Rec.Left;
    ATarget.Height := Rec.Bottom - Rec.Top;

    BitBlt(ATarget.Canvas.Handle, 0, 0, ATarget.Width, ATarget.Height, SourceDC, 0, 0, SRCCOPY);
  finally
    ReleaseDC(tmpHandel, SourceDC);
  end;
end;

Aufruf z.B.

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  tmpBitMap : TBitMap;
begin
  tmpBitMap := TBitMap.Create;
  try
    case RadioGroup1.ItemIndex of
     0 : MakeScreenShot(tmpBitMap, sssPrimaryScreen);
     1 : MakeScreenShot(tmpBitMap, sssDesktopScreen);
     2 : MakeScreenShot(tmpBitMap, sssActiveForm);
     3 : MakeScreenShot(tmpBitMap, sssActiveFormClient);
     else exit;
    end;
    Image1.Picture.Assign(tmpBitMap);
  finally
    tmpBitMap.Free;
  end;
end;
  Mit Zitat antworten Zitat