Autor Beitrag
Nicor
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Do 08.09.05 11:38 
Hallo ich bin gerade dabei mir ein Programm zu schreiben welches ein Symbol in die Systray legt und ansonsten nicht weiter sichtbar ist. Wenn man auf das Icon in der Systray klickt soll ein Screenshot vom aktuellen Fenster gemacht werden und der dann gespeichert werden. (Sinn von dem Programm ist es Screenshots von Fehlermeldungen zu machen).

Ich habe mir die wichtigen Sachen hier im Forum zusammengesucht und zusammenkopiert.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.CoolTrayIcon1Startup(Sender: TObject;
  var ShowMainForm: Boolean);
begin
ShowMainForm := false;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure ScreenShotActiveWindow(Bild: TBitMap);
var  
  c : TCanvas;
  r, t : TRect;
  h : THandle;
begin
  c := TCanvas.Create;
  c.Handle := GetWindowDC(GetDesktopWindow);
  h := GetForeGroundWindow;
  if h<>0 then
    GetWindowRect(h, t);  
  try
    r := Rect(0,0,t.Right-t.left, t.Bottom-t.Top);
    Bild.Width := t.Right-t.left;
    Bild.Height := t.Bottom-t.Top;
    Bild.Canvas.CopyRect(r, c, t);
  finally  
    ReleaseDC(0, c.handle);  
    c.Free;  
  end;  
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.CoolTrayIcon1Click(Sender: TObject);
var pic : TBitMap
begin

ScreenShotActiveWindow(pic);
pic.SaveToFile('c:\test.bmp');

end;

end.


Wie es aussieht habe ich beim Aufruf irgendwas verafft, da ich jedesmal wenn ich auf das Icon klicke einen Fehler bekomme.

Ich danke schonmal für die Hilfe

Mfg
s-off
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 35

WinXP
D7 Prof
BeitragVerfasst: Do 08.09.05 11:51 
vielleicht solltest du dein problem etwas spezifizieren ^^

es macht sich sicherlich niemand die mühe, deinen code durchzulesen, geschweige denn in delphi einzubauen, wenn er nicht weiss, was für eine fehlermeldung du bekommst - oder vielleicht doch?!

_________________
greetz
s-off


Zuletzt bearbeitet von s-off am Do 08.09.05 11:54, insgesamt 1-mal bearbeitet
laserflor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 37

Win XP, Win 2000, Win 98, Win NT4
D5 Prof
BeitragVerfasst: Do 08.09.05 11:53 
Hallo Nicor

kleiner Tipp: Hinweise einschalten ;-)

pic ist nicht initialisiert

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.CoolTrayIcon1Click(Sender: TObject);
var pic : TBitMap;
begin
pic:= TBitmap.Create;
ScreenShotActiveWindow(pic);
pic.SaveToFile('c:\test.bmp');

end;


So sollte es funktionieren (bei mir tut's) :D

Gruß Rolf

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Fr 09.09.05 14:12 
Dann solltest du es nach dem Speichern aber auch wieder mit pic.Free freigeben.
Sonst frisst dein Programm ein riesiges Loch in den Speicher.

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)