Autor Beitrag
Andi1982
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 497

WinXP HE
D6 Enterprise
BeitragVerfasst: Sa 12.06.04 15:40 
Hallo,
ich möchte mit meinem programm einen Screenshot eines anderen Programms machen. Das mache ich folgendermaßen:

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:
procedure TForm1.Button2Click(Sender: TObject);
var testhand: HWND;
begin
  testhand := StrToInt(ListView1.Items[Listview1.selected.Index].Caption);
  FormularSaveScreenShot('e:\temp\formshot.bmp', testhand);
end;

function FormularSaveScreenShot(FileName: String; h : hWnd): Boolean;
var
  Rec: TRect;
  iWidth, iHeight: Integer;
begin
  with TBitmap.Create 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;


    try SaveToFile(Filename) except Result := False end;
  finally
    ReleaseDC(h, GetWindowDC(h));
    Free;
  end;
end;


Mein problem ist jetzt: Wenn ich den Button für den Screenshot drücke wird ein Screenshot erstellt, ABER leider ist da mein programm ja noch im Vordergrund und das ist dann im BMP zu sehen.

Wie kann ich die Anwendung, zu der ich das Handle habe, in den vordergrund holen?

Hoffe jemand kann mir helfen.

_________________
Solange die Bombe tickt ist alles in Ordnung, erst wenn sie damit aufhört wird es problematisch...
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Sa 12.06.04 17:09 
Das ist die Lösung vom Swissdelphicenter.

Mein Favorit ist Lsg. 2:
ausblenden 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:
// 2. Way: 
//********************************************** 

procedure ForceForegroundWindow(hwnd: THandle); 
  // (W) 2001 Daniel Rolf 
  // http://www.finecode.de 
  // rolf@finecode.de 
var 
  hlp: TForm; 
begin 
  hlp := TForm.Create(nil); 
  try 
    hlp.BorderStyle := bsNone; 
    hlp.SetBounds(0, 0, 1, 1); 
    hlp.FormStyle := fsStayOnTop; 
    hlp.Show; 
    mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); 
    mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); 
    SetForegroundWindow(hwnd); 
  finally 
    hlp.Free; 
  end; 
end;
Andi1982 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 497

WinXP HE
D6 Enterprise
BeitragVerfasst: So 13.06.04 00:55 
Vielen Dank Karlson,
jetzt hat es funktioniert!

_________________
Solange die Bombe tickt ist alles in Ordnung, erst wenn sie damit aufhört wird es problematisch...
Markus123
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 35


Delphi 2007
BeitragVerfasst: Mi 23.03.05 11:42 
Hallo zusammen,

ich habe die verschiedensten Force-Möglichkeiten der Web-Seite ausprobiert: Nichts funktioniert :(

Ich habe zwischenzeitlich die Vermutung, dass ich das Handle falsch ermittle:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
try
  hProcess:= CreateToolHelp32SnapShot(TH32CS_SNAPALL, 0);
  if hProcess > 0 then
  begin
    Proc.dwSize:= SizeOf(TProcessEntry32);
    Process32First(hProcess, Proc);
    repeat
      if AnsiCompareText(ExtractFileName(Proc.szExeFile), Name) = 0 then
      begin
        Result:= Proc.th32ProcessID;
        Exit;
      end;
    until (not Process32Next(hProcess, Proc));
  end;
 except
 Result:= 0;
end;


Mit dem Result meiner Funktion rufe ich nun die ForceForegroundWindow-Proceduren auf mit dem Ergebnis, dass das Programm nicht im Vordergrund ist. Kann mir jemand helfen? Besten Dank!

Grüße,
Markus

PS: Grundinfos: Windows 2000 (SP4), Delphi 4.0 Pro

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.