Autor Beitrag
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Mo 14.03.11 09:54 
Hi Leute,

habe ein sehr seltsames Problem, ich habe folgenden Code
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Procedure BildAusSchnitt(hWND: HWND; iLeft, iTop, iWidth, iHeight, faktor: integer);
var c: TCanvas;
begin
  BringWindowToTop(hWND);
  c:= TCanvas.Create; 
  c.Handle:= GetWindowDC(hWND);
  try
    printer.orientation := poLandscape;
    printer.begindoc;
    printer.Canvas.CopyRect(Rect(00, iWidth* faktor, iHeight* faktor), c, Rect(iLeft, iTop, iLeft+ iWidth, iTop+ iHeight));
    printer.enddoc;
  finally
    ReleaseDC(hWND, c.handle); 
    c.Free; 
  end;
end;

den hab ich von hier www.delphipraxis.net...ken-inkl-kompos.html "geklaut"
und so ruf ich ihn auf
ausblenden Delphi-Quelltext
1:
  BildAusSchnitt(Panel6.Handle, 226005007);					

und das hat auch mal funktioniert. Delphiversion ist D2007. Seltsamerweise scheint er jetzt aber nicht mehr zu funktionieren und ich raff nicht warum. Win7 erzeigt Zugriffsverletzungen und auf einem XP-Rechner kommt nur ein leeres Blatt raus :( Kann das mal jemand versuchen zu replizieren? Ich bin sicher, dass der Code funktioniert hat und ich daran auch nichts geändert habe, ausser ihn diverse mal neu compiliert zu haben. :( :( :(

_________________
mfg. Joel
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mo 14.03.11 10:03 
Ich hab kein Delphi und kann es daher auch nicht testen, aber wie wär's denn mit der Methode TWinControl.PaintTo? Da kannst du einen Canvas eingeben, in das das Control gezeichnet werden soll. Dann kannst du das Panel sogar drucken, wenn das Fenster gerade nicht im Vordergrund ist.
JoelH Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Mi 16.03.11 09:22 
Das Problem hierbei ist, dass das ganze Teil gedruckt wird, ich aber nur einen bestimmten Ausschnitt benötige.

Edit:
Okay das Ausschnittsproblem hab ich nun gelöst, aber dafür ist ein andereres Problem aufgetreten. Auf dem Panel liegen Edits, Combos und auch Richedits Komponenten drauf. Leider wird der Inhalt der Comboboxen und Richedits nicht in die Bitmap übernommen :(

_________________
mfg. Joel
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 16.03.11 12:39 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Procedure CompletePaintTo(C:TwinControl;Dest:TCanvas;x,y:Integer);
// 20110316 by Thomas Wassermann
var
  i:Integer;
  DC:HDC;
begin
   c.PaintTo(Dest,x,y);
   for I := 0 to C.ControlCount- 1 do
      if c.Controls[i] is TCustomEdit then
        begin
          DC :=  TCustomEdit(c.Controls[i]).Handle);
          BitBlt(Dest.Handle,
                 x + c.Controls[i].Left, y +  c.Controls[i].Top
                 , c.Controls[i].Width,  c.Controls[i].Height,DC,0,0,SRCCOPY);
          ReleaseDC(TCustomEdit(c.Controls[i]).Handle,DC);
        end;
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS


Zuletzt bearbeitet von bummi am Mi 16.03.11 18:15, insgesamt 1-mal bearbeitet
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mi 16.03.11 17:26 
user profile iconbummi: Funktioniert deine Variante auch, wenn das Fenster teilweise verdeckt ist? In der Beschreibung von BitBlt steht:

Zitat:
The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.

Ich würde folgende Methode probieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure RecursivePaintTo(Control: TWinControl; Canvas: TCanvas, X, Y: Integer);
var i: Integer;
begin
  Control.PaintTo(Canvas, X, Y);
  for i := 0 to Control.ControlCount - 1 do
  begin
    if Control is TWinControl then
      RecursivePaintTo(Control.Controls[i], Canvas, Control.Left, Control.Top);
  end;
end;

Solange nur Edits, ComboBoxen und RichEdits - also alles WinControls - in dem Panel sind, dürfte es so klappen. Wie es mit Labels aussieht, weiß ich aber nicht.
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 16.03.11 18:46 
@YOGU
geht auch wenn Quelle oder Ziel verdeckt sind, habe das Nesting noch nachgerüstet, Problem war ja dass Text aus Richedits bei alleinigem PaintTo nicht mitkommt
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Procedure CompletePaintTo(C:TwinControl;Dest:TCanvas;x,y:Integer;First:Boolean=true);
// 20110316 by Thomas Wassermann
var
  i:Integer;
  DC:HDC;
begin
   if First then c.PaintTo(Dest,x,y);
   for I := 0 to C.ControlCount- 1 do
      if c.Controls[i] is TCustomEdit then
        begin
          DC :=  GetDC(TCustomEdit(c.Controls[i]).Handle);
          BitBlt(Dest.Handle,
                 x + c.Controls[i].Left, y +  c.Controls[i].Top
                 , c.Controls[i].Width,  c.Controls[i].Height,DC,0,0,SRCCOPY);
          ReleaseDC(TCustomEdit(c.Controls[i]).Handle,DC);
        end  else if c.Controls[i] is TWinControl then CompletePaintTo(TWinControl(c.Controls[i]),Dest,x + c.Controls[i].Left,y + c.Controls[i].Top,false)
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS