Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Wie man das Handle von einem Screenshot entfernt (https://www.delphipraxis.net/195187-wie-man-das-handle-von-einem-screenshot-entfernt.html)

victorlus 9. Feb 2018 12:48

Delphi-Version: XE5

Wie man das Handle von einem Screenshot entfernt
 
Hallo an alle, ich brauche einen Druckbildschirm, indem ich mein Hauptformular entferne
Ich habe versucht, Magnification.pas zu verwenden, aber ich konnte es nicht sehr gut verwenden
Wer kennt keine Lösung, Was funktioniert bei Win 7, Win 8, Win 10?

Oder hilf mir in ein paar Tipps :)
Vielen Dank im Voraus.

Neutral General 9. Feb 2018 12:50

AW: Wie man das Handle von einem Screenshot entfernt
 
Blende das was du nicht auf dem Screenshot haben willst aus, mach den Screenshot und danach blendest du die Formulare/Controls wieder ein.

hoika 9. Feb 2018 12:54

AW: Wie man das Handle von einem Screenshot entfernt
 
Hallo,
was ist denn ein "Druckbildschirm"?
Was soll den konkret nicht angezeigt werden, wirklich das Hauptfenster Deines Programms?

victorlus 9. Feb 2018 12:57

AW: Wie man das Handle von einem Screenshot entfernt
 
Zitat:

Zitat von Neutral General (Beitrag 1393446)
Blende das was du nicht auf dem Screenshot haben willst aus, mach den Screenshot und danach blendest du die Formulare/Controls wieder ein.

Versteckt, die Form nach dem Zeigen wäre keine gute Option für mich :(

victorlus 9. Feb 2018 12:58

AW: Wie man das Handle von einem Screenshot entfernt
 
Zitat:

Zitat von hoika (Beitrag 1393447)
Hallo,
was ist denn ein "Druckbildschirm"?
Was soll den konkret nicht angezeigt werden, wirklich das Hauptfenster Deines Programms?

Ja das Formular, Prinzipal oder andere spezifische Form

hoika 9. Feb 2018 13:32

AW: Wie man das Handle von einem Screenshot entfernt
 
Hallo,
aha, und was soll denn dann angezeigt werden, ein über das Hauptform geöffnete 2. Form?

Brauchst Du Screenshots für ein Handbuch, oder was ist das Ziel??

victorlus 9. Feb 2018 13:39

AW: Wie man das Handle von einem Screenshot entfernt
 
Zitat:

Zitat von hoika (Beitrag 1393454)
Hallo,
aha, und was soll denn dann angezeigt werden, ein über das Hauptform geöffnete 2. Form?

Brauchst Du Screenshots für ein Handbuch, oder was ist das Ziel??

Ich muss einen Druckbildschirm vom Formular zurückbekommen, ohne mich zu verstecken, dann zeige das Formular wieder, das auf win7, win8, win10 funktioniert
Tut mir leid, wenn es schlecht ist, ich kann kein Deutsch.

Neutral General 9. Feb 2018 13:39

AW: Wie man das Handle von einem Screenshot entfernt
 
Noch eine Anmerkung:
Falls du Englisch sprichst, schreib lieber in Englisch.
Google Translate werden die meisten hier schlechter verstehen als halbwegs ordentliches Englisch.

victorlus 9. Feb 2018 13:46

AW: Wie man das Handle von einem Screenshot entfernt
 
Zitat:

Zitat von Neutral General (Beitrag 1393456)
Noch eine Anmerkung:
Falls du Englisch sprichst, schreib lieber in Englisch.
Google Translate werden die meisten hier schlechter verstehen als halbwegs ordentliches Englisch.

Sorry, friend I need to take a screenshot, behind the form without hiding the form, shows it again.

hoika 9. Feb 2018 14:10

AW: Wie man das Handle von einem Screenshot entfernt
 
Hello, ;)
you need DelphiCode to get the screenshot or just want the screenshot?

If you only want to take a screenshot, move the form out of the screen und use a snipping tool to get the screenshot.
Windows has a build in snipping tool.

I do not understand the "shows it again".

victorlus 9. Feb 2018 14:19

AW: Wie man das Handle von einem Screenshot entfernt
 
Zitat:

Zitat von hoika (Beitrag 1393462)
Hello, ;)
you need DelphiCode to get the screenshot or just want the screenshot?

If you only want to take a screenshot, move the form out of the screen und use a snipping tool to get the screenshot.
Windows has a build in snipping tool.

I do not understand the "shows it again".

I can not move the form, or hide it needs to stay, visible to the client I'm going to capture the screen that is behind him

Example:

prntscr.com/314rix - SUCESS IN WIN7

prntscr.com/314tj7 - FAILED IN WIN8

prntscr com/31502u - SUSPEND WINLOGON.EXE and KILL DWM.EXE IN WIN8

Neutral General 9. Feb 2018 14:21

AW: Wie man das Handle von einem Screenshot entfernt
 
Okay maybe you should show us the code you are using (which seems to work on Win7 but noch on Win8).

victorlus 9. Feb 2018 14:51

AW: Wie man das Handle von einem Screenshot entfernt
 
Zitat:

Zitat von Neutral General (Beitrag 1393464)
Okay maybe you should show us the code you are using (which seems to work on Win7 but noch on Win8).


Put the form in ALPHABLEND = TRUE;


Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,
  Clipbrd;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    ScrollBox1: TScrollBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure ScreenShot(DestBitmap: TBitmap);
var
  DC: HDC;
begin
  DC:=GetDC(GetDesktopWindow);
  try
    DestBitmap.Width:=GetDeviceCaps(DC, HORZRES);
    DestBitmap.Height:=GetDeviceCaps(DC, VERTRES);
    BitBlt(DestBitmap.Canvas.Handle,0,0,DestBitmap.Width,DestBitmap.Height,DC,0,0,SRCCOPY);
  finally
    ReleaseDC(GetDesktopWindow, DC);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ScreenShot(Image1.Picture.Bitmap);
end;

end.

Delphi.Narium 9. Feb 2018 15:02

AW: Wie man das Handle von einem Screenshot entfernt
 
You can get a Hardcopy using Method GetFormImage from TForm.

http://docwiki.embarcadero.com/CodeE...mImage_(Delphi)
Zitat:

Zitat von GetFormImage
Description

This example uses an image, a button, and a shape component on a form. When you click the button, an image of the form is stored in the FormImage variable and copied to the Clipboard. The image of the form is then copied back to the image component, producing an interesting result, especially if the button is clicked multiple times. Add ExtCtrls, StdCtrls, and Clipbrd to the uses clause.

Delphi-Quellcode:
procedure HardCopy(sJpegFile : String; fm : TForm);
Var
          FStream  : TStream;
          FBmp     : TPicture;
          FJpeg    : TJpegImage;
begin
  if SysUtils.FileExists(sJpegFile) then SysUtils.DeleteFile(sJpegFile);
  FStream := TFileStream.Create(sJpegFile,fmCreate);
  fm.WindowState := wsNormal;
  fm.Show;
  fm.Refresh;
  FJpeg := TJpegImage.Create;
  FBmp := TPicture.Create;
  try
    FBmp.Bitmap.Assign(fm.GetFormImage); // <- get a Hardcopy from TForm
    FJpeg.Assign(FBmp.Bitmap);
    FJpeg.SaveToStream(FStream);
  finally
    FStream.Free;
    FJpeg.Free;
    FBmp.Free;
  end;
end;
Not tested:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,
  Clipbrd;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    ScrollBox1: TScrollBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure ScreenShot(DestBitmap: TBitmap; fm : TForm);
begin
  DestBitmap.Assign(fm.GetFormImage); // <- get a Hardcopy from TForm
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ScreenShot(Image1.Picture.Bitmap; Form1); // <-- or any other TForm
end;

end.

victorlus 9. Feb 2018 16:59

AW: Wie man das Handle von einem Screenshot entfernt
 
Zitat:

Zitat von Delphi.Narium (Beitrag 1393468)
You can get a Hardcopy using Method GetFormImage from TForm.

http://docwiki.embarcadero.com/CodeE...mImage_(Delphi)
Zitat:

Zitat von GetFormImage
Description

This example uses an image, a button, and a shape component on a form. When you click the button, an image of the form is stored in the FormImage variable and copied to the Clipboard. The image of the form is then copied back to the image component, producing an interesting result, especially if the button is clicked multiple times. Add ExtCtrls, StdCtrls, and Clipbrd to the uses clause.

Delphi-Quellcode:
procedure HardCopy(sJpegFile : String; fm : TForm);
Var
          FStream  : TStream;
          FBmp     : TPicture;
          FJpeg    : TJpegImage;
begin
  if SysUtils.FileExists(sJpegFile) then SysUtils.DeleteFile(sJpegFile);
  FStream := TFileStream.Create(sJpegFile,fmCreate);
  fm.WindowState := wsNormal;
  fm.Show;
  fm.Refresh;
  FJpeg := TJpegImage.Create;
  FBmp := TPicture.Create;
  try
    FBmp.Bitmap.Assign(fm.GetFormImage); // <- get a Hardcopy from TForm
    FJpeg.Assign(FBmp.Bitmap);
    FJpeg.SaveToStream(FStream);
  finally
    FStream.Free;
    FJpeg.Free;
    FBmp.Free;
  end;
end;
Not tested:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,
  Clipbrd;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    ScrollBox1: TScrollBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure ScreenShot(DestBitmap: TBitmap; fm : TFrom);
begin
  DestBitmap.Assign(fm.GetFormImage); // <- get a Hardcopy from TForm
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ScreenShot(Image1.Picture.Bitmap; Form1); // <-- or any other TForm
end;

end.


Do not work I need to take photo behind the form

Thank you for trying to help me.

Uwe Raabe 9. Feb 2018 17:12

AW: Wie man das Handle von einem Screenshot entfernt
 
As it seems to turn out hard to make it work under the different Windows versions, can you explain what you are trying to achieve in the end? What do you need this screenshot of the area behind the form for?

victorlus 9. Feb 2018 17:18

AW: Wie man das Handle von einem Screenshot entfernt
 
Zitat:

Zitat von Uwe Raabe (Beitrag 1393481)
As it seems to turn out hard to make it work under the different Windows versions, can you explain what you are trying to achieve in the end? What do you need this screenshot of the area behind the form for?

Yes, I need exactly this :) More really is very complicated

Delphi.Narium 9. Feb 2018 17:25

AW: Wie man das Handle von einem Screenshot entfernt
 
Please remove
Delphi-Quellcode:
fm.Show;
from
Delphi-Quellcode:
procedure HardCopy
Does it work?

Sorry for my poor english.

victorlus 9. Feb 2018 18:17

AW: Wie man das Handle von einem Screenshot entfernt
 
I'm trying to use it, magnification but the screen comes out all black someone has a solution
?



Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Magnification, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    Initialized: BOOL;
    magWindowRect: TRect;
    hwndMag: HWND;
    HandleToMagnifier: HWND;
    function MyCreateDIBSection(DC: HDC; Width, Height: integer; BitCount: integer): HBITMAP;
    procedure DrawMagnifier(Width, Height: Integer);
    procedure RefreshMagnifier(rc:TRect);
   // procedure ResizeMagnifier;
    procedure InitializeMagnifier;
  public
    { Public declarations }
  end;


const
  MagFactor = 2.0;

var
  Form1: TForm1;


implementation

{$R *.dfm}


function TForm1.MyCreateDIBSection(DC: HDC; Width, Height, BitCount: integer): HBITMAP;
var
  lpbmi: TBitmapInfo;
  P: Pointer;
  AbITmAP : hbitmap;
  db : tbitmap;

begin

  Fillchar(lpbmi, SizeOf(TBitmapInfo), 0);
  lpbmi.bmiHeader.biSize := sizeof(lpbmi.bmiHeader);
  lpbmi.bmiHeader.biHeight := - Height;
  lpbmi.bmiHeader.biWidth := width;
  lpbmi.bmiHeader.biPlanes := 1;
  lpbmi.bmiHeader.biBitCount := BitCount;
  lpbmi.bmiHeader.biCompression := BI_RGB;

  Result := CreateDIBSection(DC, lpbmi, DIB_RGB_COLORS, P, 0, 0);
end;

procedure TForm1.DrawMagnifier(Width, Height: Integer);
var
  aBitmap: HBITMAP;
  DC: HDC;
  bmp: TBitmap;
begin

  DC := GetWindowDC(HwndMag);
  bmp := TBitmap.Create;
  aBitmap := 0;
  try
    aBitmap := Form1.MyCreateDIBSection(DC, Width, Height, 32);
    SelectObject(DC, aBitmap);
    bmp.Handle := aBitmap;
    bmp.SaveToFile('Screen.bmp');
  finally
    DeleteObject(aBitmap);
    DeleteDC(DC);
    bmp.Free;
  end;
end;

procedure TForm1.RefreshMagnifier(rc: TRect);
begin

  MagSetWindowSource(hwndMag, rc);
  SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);

  InvalidateRect(hwndMag, rc, true);
end;


procedure TForm1.InitializeMagnifier;
var
  matrix: TMagTransform;
    desktop : hwnd;
  desktoprect, sourceRect: TRect;
  filterList: THWNDArray;
  m_ScreenX, m_ScreenY, m_ScreenT, m_ScreenL: Integer;
begin

   desktop := GetDesktopWindow;
  GetWindowRect(desktop, desktoprect);

  m_ScreenT := desktoprect.Top;
  m_ScreenL := desktoprect.Left;
  m_ScreenX := desktoprect.right;
  m_ScreenY := desktoprect.bottom;

  hwndMag := CreateWindow(WC_MAGNIFIER, 'MagnifierWindow',
    WS_CHILD or MS_SHOWMAGNIFIEDCURSOR, 0, 0, m_ScreenX,
    m_ScreenY, Form1.handle, 0, hInstance, nil);

  if hwndMag = 0 then
    close;

  FillChar(matrix, Sizeof(matrix), 0);
  matrix.v[0][0] := MagFactor;
  matrix.v[1][1] := MagFactor;
  matrix.v[2][2] := 1.0;
  if MagSetWindowTransform(hWndMag, matrix) then
//    tmr1.Enabled := true;
end;



procedure MagScreenShot;
var
  desktop : hwnd;
  desktoprect, sourceRect: TRect;
  filterList: THWNDArray;
  m_ScreenX, m_ScreenY, m_ScreenT, m_ScreenL: Integer;
begin

  Form1.WindowState := wsMaximized;

  desktop := GetDesktopWindow;
  GetWindowRect(desktop, desktoprect);

  Form1.DrawMagnifier(desktoprect.Right, desktoprect.Bottom);
  Form1.RefreshMagnifier(desktoprect);

end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  MagScreenShot;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin

 Initialized := MagInitialize;
  if not Initialized then
  begin
    Application.MessageBox('Init magnification failed', 'Error',
      mb_Ok + mb_IconError);
    close;
  end;

  InitializeMagnifier;


end;


procedure TForm1.FormDestroy(Sender: TObject);
begin
  if (initialized) then
    MagUninitialize;
end;

end.


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:20 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz