Autor Beitrag
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 22.01.06 10:47 
Hallo, ich wollte zu meinen Delphi Tools ein Programm hinzufügen, welches wenn mein programm gestartet ist, automatisch einen screenshot des fensters macht und diesen im programmverzeichnis speichert, als parameter übergebe ich die exe (Tools -> Makros EXENAME)

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:
program progscreen;

{$APPTYPE CONSOLE}

uses
  Windows,
  SysUtils,
  Graphics;

var
  aDC: HDC;
  aHandle: THandle;
  aRect: TRect;
  aBMP: TBitmap;
begin
  if not fileexists(paramstr(1)) then
  begin
    writeln('Die Datei existiert nicht!');
    exit;
  end;

  aHandle := findwindow(nil, pchar(paramstr(1)));

  if aHandle = 0 then
  begin
    writeln('Keine gültige Fensteranwendung!');
    exit;
  end;

  GetWindowRect(aHandle, aRect);
  aDC := CreateDC('DISPLAY', nil, nil, nil);
  aBMP := TBitmap.Create;
  try
    aBMP.PixelFormat := pfDevice;
    aBMP.Width := aRect.Right - aRect.Left;
    aBMP.Height := aRect.Bottom - aRect.Top;
    BringWindowToTop(aHandle);
    BitBlt(aBMP.Canvas.Handle, aRect.Left, aRect.Top, aBMP.Width, aBMP.Height, aDC, 0, 0, SRCCOPY);
    aBMP.SaveToFile(extractfilepath(paramstr(1)) + 'screen.bmp');
  finally
    DeleteDC(aDC);
    aBMP.Free;
  end;
end.

jedoch scheint er das handle nicht zu finden, nehme ich stattdessen paramstr(0) also die eigene anwendung, dann klappt das ganze wunderbar (also das handle wird gefunden). wo liegt also der fehler ?

vielen dank schonmal ;)
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 22.01.06 15:18 
Hast du dir mal ParamStr(1) ausgeben lassen?

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 22.01.06 15:19 
ist korrekt, frage oben ja auch die datei auf existenz ab
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: So 22.01.06 17:10 
Hallo,

mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
  astr := extractFileName(Paramstr(1));
  astr:= changeFileExt(astr,'');

  aHandle := findwindow(nil, pchar(aStr));

erhalte ich das richtige handle des Programmes, aber nicht des Fensters 'Form1'.
Wenn ich einfach nach 'Form1' suche funktioniert es auch nicht richtig, da die Daten der Groesse nach zwar richtig sind, aber ein Schnappschusz ab der Desktopposition 0,0 und nicht vom Fenster selbst gemacht wird.,
Zudem ist das Fenster nicht im Vordergrund.
Nun da musst Du wohl noch etwas suchen
www.delphipraxis.net/viewtopic.php?t=4126

Gruss Horst
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 22.01.06 17:14 
normalerweise setze ich das fenster ja in den vordergrund und das ding ist, dass das mit paramstr(0) funktioniert.
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: So 22.01.06 18:04 
bei der konsolenanwendung steht auch im titel des konsolenfenster der exename...

wenn du unbedingt über den exenamen vorgehen willst, solltest du EnumThreadWindows verwenden.
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 22.01.06 19:02 
Also nochmal genau was ich vorhabe:

Ein Programm, dem ich als paramstr() ein anderes Programm übergebe, vom hauptfenster dieses programms soll ein screenshot gemacht werden.

Das ganze wollte ich unter Tools bei Delphi einbinden und da kann man nunmal nur den exe namen übergeben.

Ziel ist es, mein programm zu kompilieren, dann auf mein tool klicken und ich habe den screenshot meines programms, da ich diese sonst immer mit mühen selbst machen müsste.
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: So 22.01.06 20:30 
warum so kompliziert ?
mach halt nen hotkey, der dir das ForeGroundWindow screenshotet
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 23.01.06 14:48 
das fenster ist nicht im vordergrund, wenn ich es nämlich kompiliere und dann bei delphi auf tools klicke ist es hinter delphi.
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: Mo 23.01.06 18:13 
wenn du den hotkey machst brauchst du aber nicht mehr auf tools klicken.
programm läuft im HG und wartet auf Hotkey, welchen du drückst wenn dein neucompiliertes teil im vordergrund ist