Autor Beitrag
DiamondDog
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Fr 24.10.08 10:54 
Hallo Leute,
ich hab da ein Problem und zwar mache ich folgender maßen einen Screenshot:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
function FormularScreenShot(Bmp: TBitmap; h : hWnd): Boolean;
var
  Rec: TRect;
  iWidth, iHeight: Integer;
begin
  with Bmp do try
    GetWindowRect(h, Rec);

    iWidth  := Rec.Right - Rec.Left;
    iHeight := Rec.Bottom - Rec.Top;

    Width := iWidth;
    Height := iHeight;

    BitBlt(Canvas.Handle, 0, 0, iWidth, iHeight, GetWindowDC(h), 0, 0, SRCCOPY);

    Result := True;
  finally
    ReleaseDC(h, GetWindowDC(h));
  end;
end;

{*************************************************************}
procedure TForm1.ScreenShot;
var
  Bmp: TBitmap;
begin
  Bmp := TBitmap.Create;
  try
    self.WindowState:=wsMinimized;              // Eigenes Fenster minimieren
    FormularScreenShot(Bmp, GetDesktopWindow);  
    self.WindowState     := wsMaximized;        // Eigenes Fenster maximieren
    SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE + SWP_NOMOVE + SWP_NOSIZE); // Fenster on Top
    Bmp.Width            := self.Width;         
    Bmp.Height           := self.Height;        
    Canvas.Draw(0, 0, Bmp);
  finally
    Bmp.Free;
  end;
end;
mein Problem dabei ist das wenn das Fenster minimiert wird,
es nicht ganz in der Taskleiste verschwindet sondern es ist immer noch
was vom Fenster zu sehn. (siehe Anhang)
Kann mir jemand sagen wie ich das wegbekomme?

Danke schon mal.

Mfg Dog
Einloggen, um Attachments anzusehen!
Bob Murphy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 91

XP, Ubuntu
Delphi 7 SE, Delphi 2007
BeitragVerfasst: Fr 24.10.08 12:52 
Versuchs mal mit Application.Minimize; damit sollte es klappen.
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Fr 24.10.08 13:20 
Damit geht es leider nicht, dann ist das ganze grau.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.10.08 13:46 
Und damit?
ausblenden Delphi-Quelltext
1:
Perform(WM_SYSCOMMAND,SC_MINIMIZE,0);					
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Fr 24.10.08 14:17 
Das funktoniert zwar:
ausblenden Delphi-Quelltext
1:
Perform(WM_SYSCOMMAND,SC_MINIMIZE,0);					
hab dann aber immer noch, das selbe Problem.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.10.08 14:19 
Verstehe ich nicht, zeig doch mal den aktuellen Code.
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Fr 24.10.08 14:22 
Das wäre der aktuelle Code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
function FormularScreenShot(Bmp: TBitmap; h : hWnd): Boolean;
var
  Rec: TRect;
  iWidth, iHeight: Integer;
begin
  with Bmp do try
    GetWindowRect(h, Rec);

    iWidth  := Rec.Right - Rec.Left;
    iHeight := Rec.Bottom - Rec.Top;

    Width := iWidth;
    Height := iHeight;

    BitBlt(Canvas.Handle, 0, 0, iWidth, iHeight, GetWindowDC(h), 0, 0, SRCCOPY);

    Result := True;
  finally
    ReleaseDC(h, GetWindowDC(h));
  end;
end;

{*************************************************************}
procedure TForm1.ScreenShot;
var
  Bmp: TBitmap;
begin
  Bmp := TBitmap.Create;
  try
    Perform(WM_SYSCOMMAND,SC_MINIMIZE,0);       
    FormularScreenShot(Bmp, GetDesktopWindow);  
    self.WindowState     := wsMaximized;     
    SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE + SWP_NOMOVE + SWP_NOSIZE);
    Bmp.Width            := self.Width;      
    Bmp.Height           := self.Height;     
    Canvas.Draw(0, 0, Bmp);
  finally
    Bmp.Free;
  end;
end;
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.10.08 14:26 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.ScreenShot;
var
  Bmp: TBitmap;
begin
  Bmp := TBitmap.Create;
  try
    Application.Minimize;
    FormularScreenShot(Bmp, GetDesktopWindow);
    Application.Restore;
    Bmp.Width            := self.Width;      
    Bmp.Height           := self.Height;     
    Canvas.Draw(0, 0, Bmp);
  finally
    Bmp.Free;
  end;
end;
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Fr 24.10.08 14:30 
@ DeddyH so ist das ganze Bild wieder grau.

Ich glaub ich hab ne Lösung:
Ich baue nach dem minimieren einen Timer ein,
der dem Fenster etwas Luft verschaft sich zu schließen.
Das funktioniert dann.

Somit würde ich sagen Problem gelöst!
Trozdem Danke an alle fürs Helfen.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.10.08 14:32 
Mal die Bitmap doch OnPaint auf das Formular.
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Fr 24.10.08 14:37 
So in etwar:
ausblenden Delphi-Quelltext
1:
self..OnPaint := bmp;					
sorry weiß nit genau wie das geht.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.10.08 14:46 
Beispiel (komplette Unit):
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    //die folgenden Methoden sind über den Objektinspektor zugewiesen
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { Private-Deklarationen }
    FBitmap: TBitmap;
    procedure ScreenShot;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function FormularScreenShot(Bmp: TBitmap; h : hWnd): Boolean;
var
  Rec: TRect;
  iWidth, iHeight: Integer;
begin
  with Bmp do try
    GetWindowRect(h, Rec);

    iWidth  := Rec.Right - Rec.Left;
    iHeight := Rec.Bottom - Rec.Top;

    Width := iWidth;
    Height := iHeight;

    BitBlt(Canvas.Handle, 0, 0, iWidth, iHeight, GetWindowDC(h), 0, 0, SRCCOPY);

    Result := True;
  finally
    ReleaseDC(h, GetWindowDC(h));
  end;
end;

{*************************************************************}
procedure TForm1.ScreenShot;
begin
  Hide;
  Sleep(100); //Momentchen warten
  FormularScreenShot(FBitmap, GetDesktopWindow);
  Show;
  FBitmap.Width            := self.Width;
  FBitmap.Height           := self.Height;
  Invalidate;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  FBitmap := TBitmap.Create;
end;

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

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

procedure TForm1.FormPaint(Sender: TObject);
begin
  BitBlt(Canvas.Handle,0,0,ClientWidth,ClientHeight,FBitmap.Canvas.Handle,0,0,SRCCOPY);
end;

end.
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Fr 24.10.08 15:02 
Also wenn ich den Code übernehmen,
kommt folgender Fehler beim straten der exe:
Eigenschaft Visible kann in OnShow oder OnHide nicht verändert werden.

Wenn ich dann auf Ok klicke is der Screen grau.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.10.08 15:24 
Machst Du OnShow einen Screenshot?
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Fr 24.10.08 15:26 
user profile iconDeddyH hat folgendes geschrieben Zum zitierten Posting springen:
Machst Du OnShow einen Screenshot?

Ja hatte ich den fehler hab ich aber gefunden,
jetzt ist nur immer noch alles grau.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.10.08 15:29 
Wo rufst Du denn jetzt die Prozedur Screenshot auf?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 24.10.08 15:42 
Das sieht für mich so aus, als würde da ein Nebenfenster (also nicht Mainform) minimiert werden. Diese Dinger bleiben über der Tastkleiste kleben, da sie sonst ja nicht wieder hochgeholt werden können, da sie keinen Eintrag in der Taskleiste haben.
Mit diesem Code
ausblenden Delphi-Quelltext
1:
SetWindowLong(Handle, GWL_ExStyle, WS_Ex_AppWindow);					
in der entsprechenden Form (ins OnShow passt das gut rein) kann man das ändern. Evtl. etwas an den Parametern schrauben. Die Suche sollte damit weiterhelfen.

_________________
We are, we were and will not be.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.10.08 15:44 
Wobei Hide und Show auch ihren Dienst tun, solange man sie nicht im OnShow-Event aufruft ;)