Autor Beitrag
Jerk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Mi 07.05.08 13:15 
Hallo, ich habe ein Programm geschrieben was von einem festgelegten Fenster einen Screenshot erstellen soll.
Es erstellt vom ausgewählten Handle ein rect und wandeld dies in eine Bitmap um.

Hier der Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
  var
   TargetHandle           : THandle;
   TargetBMP              : TBitmap;
   WindowRect             : TRect;
   WindowDC               : THandle;

...
  TargetHandle := FindWindow(nil,Windowname);
  if TargetHandle <> 0 then
  begin
   WindowDC   := GetWindowDC(TargetHandle);
   GetWindowRect(TargetHandle, WindowRect);
   TargetBMP.Width  := WindowRect.Right - WindowRect.Left;
   TargetBMP.Height := WindowRect.Bottom - WindowRect.Top;
   StretchBlt(TargetBMP.Canvas.Handle, 0, 0, TargetBMP.Width,
              TargetBMP.Height,   WindowDC  , 0, 0,TargetBMP.Width,TargetBMP.Height,
              SRCCOPY);
  end;


Es hat keine Probleme mit Spielen im Fullscreen, doch sobald das Spiel im Windowmode ist, sind auf dem Screen die Taskleiste und alle anderen Fenster zu sehen.Ab und zu erkennt er die auflösung nicht und macht nen screenshot in der größe 134*137 aber nur im Windowmode. Woran kan das liegen?
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Fr 16.05.08 00:23 
Keiner ne Idee?
gispos
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 94

WIN 7
XE10, D2007
BeitragVerfasst: Fr 16.05.08 17:08 
Versuch mal dieses, ist aus einem meiner Projekte, mußt vieleicht GetForegroundWindow
ersetzen. Versuch vieleicht das Flag für den Client-Bereich.(2)
Gib dann mal bescheid obs damit klappt.
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:
// Flag  0= Desktop; 1= ForgroundWindow; 2= ForgroundClient;
procedure MakeScreenSnapShot(const dest: TBitmap; Flag: Byte= 0);
var ScreenDC,CompDC: HDC;
    th: THandle;
    hBmp: HBitmap;
    WRect: TRect;
    w,h: Integer;
begin
   Case Flag of
     0: begin
          ScreenDC:= GetDC(0);
          w:= GetDeviceCaps(ScreenDC,HORZRES);
          h:= GetDeviceCaps(ScreenDC,VERTRES);
        end;
     1: begin
          th:= GetForegroundWindow;
          GetWindowRect(th,WRect);
          w:= WRect.Right-WRect.Left;
          h:= WRect.Bottom-WRect.Top;
          ScreenDC:= GetWindowDC(th);
        end;
     2: begin
          th:= GetForegroundWindow;
          GetClientRect(th,WRect);
          w:= WRect.Right-WRect.Left;
          h:= WRect.Bottom-WRect.Top;
          ScreenDC:= GetDC(th);
        end;
     else exit;
   end;
   CompDC:= CreateCompatibleDC(ScreenDC);
   hBmp:= CreateCompatibleBitmap(ScreenDC,w, h);
                                
   th:= SelectObject(CompDC,hBmp);
   If Dest.PixelFormat<> pf24Bit then Dest.PixelFormat:= pf24bit;
   Dest.Width:= w;
   Dest.Height:= h;
   BitBlt(CompDC,0,0,Dest.Width,Dest.Height,ScreenDC,0,0,SRCCOPY);
   // schneller als dirkt vom  ScreenDC wenn Bitmap 24 Bit sein soll
   BitBlt(Dest.Canvas.Handle,0,0,Dest.Width,Dest.Height,CompDC,0,0,SRCCOPY);

   DeleteObject(SelectObject(CompDC,th));
   DeleteDC(CompDC);
   ReleaseDC(0,ScreenDC);
   DeleteDC(ScreenDC);
end;


Gruß gispos
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Fr 23.05.08 16:15 
Vielen dank dafür, hatte leider keine Zeit das bisher zu testen werde es aber morgen in Angriff nehmen.