ich bin komplett neu in Richtung python unterwegs. Ich möchte eine Funktion, welche ich in Delphi XE verwende in python portieren, bin jedoch noch nicht fündig geworden und noch am Anfang. Anbei der Code
Funktion
- Ermittle das Handle des Fenster, welches im Vordergrund läuft - hat den Fokus
- Ermittle den Titel/Name der Applikation
- Prüfe den Name, wenn o.k.
- Ermittle die Fenstergröße
- Ermittle den DC DeviceContext um auf die Grafik zuzugreifen
- Kopiere den Bildauschnitt in ein Bitmap
- Liefere das Bitmap und den Status zurück
Code: Alles auswählen
function GetBitmap( AppName:String; x,y,w,h:Integer; BM:TBitmap ):Boolean;
var
Handle : THandle;
Title : String;
Len : LongInt;
WindowRect : TRect;
HD : HDC;
b : Boolean;
begin
b := False;
Handle := GetForegroundWindow;
if( Handle <> 0 )then
begin
Len := GetWindowTextLength( Handle ) + 1;
SetLength( Title,Len );
GetWindowText( Handle,PChar( Title ), Len );
Title := Trim( Title );
if( Title = AppName )then
begin
GetWindowRect( Handle, WindowRect );
HD := GetDC( Handle );
BM.Width := w;
BM.Height := h;
BitBlt( BM.Canvas.Handle, 0, 0, w, h, HD, WindowRect.Width - x, WindowRect.Height - y, SRCCOPY );
ReleaseDC( 0,HD );
b := True;
end;
end;
result := b;
end;
Aufruf Beispiel
Code: Alles auswählen
BM := TBitmap.Create;
if( GetBitmap( 'TEST',x,y,w,h,BM )=True )then
begin
inc( i );
PB.Canvas.Draw(0, 0, BM);
s := 'C:\TEMP\Test'+Format('%.3d', [i]) + '.BMP';
BM.SaveToFile( s );
end;
BM.Free;
Auflösung habe ich bereits
Code: Alles auswählen
from tkinter import *
root = Tk()
monitor_height = root.winfo_screenheight()
monitor_width = root.winfo_screenwidth()
print("width x height = %d x %d (pixels)" %(monitor_width, monitor_height))
mainloop()
Danke und Gruß PyChe