procedure TForm1.Button1Click(Sender: TObject);
var bmp: TBitmap;
buf: array of Byte;
res, len, bufidx, bufsize: Integer;
procedure BmpToBuf;
var i, x, y, w, h: Integer;
p: PByteArray;
begin
w:=bmp.Width;
h:=bmp.Height;
bmp.PixelFormat:=pf24bit;
i:=1234;
Move(i, buf[0], sizeof(Integer));
Move(w, buf[sizeof(Integer)], sizeof(Integer));
Move(h, buf[2*sizeof(Integer)], sizeof(Integer));
i:=sizeof(Integer)+2*sizeof(Integer);
for y:=0 to h-1 do
begin
p:=bmp.Scanline[y];
Move(p[0], buf[i], w*3);
inc(i, w*3);
end;
end;
begin
bmp:=<MacheinScreenshotvomFenster>(
Handle);
len:=sizeof(Integer)+2*sizeof(Integer)+bmp.Height*bmp.Width*3;
if len mod 1024 <> 0 then
inc(len, 1024-(len mod 1024));
SetLength(buf, len);
BmpToBuf;
bmp.Free;
if ServerSocket.Socket.ActiveConnections>0 then
begin
bufidx:=0; bufsize:=Length(buf);
while bufsize>0 do
begin
repeat
res:=ServerSocket.Socket.Connections[0].SendBuf(buf[bufidx], Min(1024, bufsize));
if res<>1024 then <MacheinePause>(50);
until res<>-1;
inc(bufidx, Min(1024, bufsize));
dec(bufsize, Min(1024, bufsize));
end;
end;
Finalize(buf);
end;