uses Clipbrd;
var
bm: TBitmap;
procedure TForm1.FormCreate(Sender: TObject);
begin
bm := TBitmap.create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
bm.free;
end;
// ----- Bitmap in die Zwischenablage stellen ----
procedure TForm1.Button1Click(Sender: TObject);
begin
bm.loadfromfile('C:Frosch.bmp'); // z.B.
clipboard.assign(bm);
end;
// ----- Bitmap in die Zwischenablage stellen ----
procedure TForm1.Button2Click(Sender: TObject);
begin
bm.loadfromfile('C:Frosch.bmp'); // z.B.
ClipBoard.Open;
Clipboard.clear;
SetClipboardData(CF_BITMAP, bm.handle);
ClipBoard.close;
end;
// ----- Bitmap aus der Zwischenablage holen ----
procedure TForm1.Button3Click(Sender: TObject);
begin
if clipboard.HasFormat(CF_BITMAP) then begin
bm.LoadFromClipBoardFormat(CF_BITMAP, Clipboard.GetAsHandle(CF_BITMAP), 0);
canvas.draw(10, 10, bm); // z.B.
end else
showmessage('Keine Bitmap in Zwischenablage');
end;
// ----- Bitmap aus der Zwischenablage holen ----
procedure TForm1.Button4Click(Sender: TObject);
begin
OpenClipBoard(Handle);
bm.Handle := HBITMAP(GetClipBoardData(CF_BITMAP));
CloseClipBoard;
if bm.Handle = 0 then
showmessage('Keine Bitmap in Zwischenablage')
else canvas.draw(10, 10, bm); // z.B.
end;
// ----- Text und Bitmap in die Zwischenablage stellen ----
procedure TForm1.Button5Click(Sender: TObject);
var
myformat: Word;
adata: THandle;
aPalette: HPalette;
begin
bm.loadfromfile('C:Frosch.bmp'); // z.B.
Clipboard.Open;
Clipboard.Clear;
Clipboard.AsText := 'DBR-Test ***;' + inttostr(clYellow); // z.B.
bm.SaveToClipboardFormat(myformat, adata, aPalette);
SetClipBoardData(CF_BITMAP, adata);
Clipboard.close;
end;
// ----- Text und Bitmap aus der Zwischenablage holen ----
procedure TForm1.Button6Click(Sender: TObject);
var
p: integer;
s: string;
begin
if not Clipboard.HasFormat(CF_BITMAP) then exit;
bm.Assign(Clipboard);
if not Clipboard.HasFormat(CF_TEXT) then exit;
s := Clipboard.asText;
if Copy(s, 1, 3) <> 'DBR' then exit;
p := pos(';', s);
Self.Caption := copy(s, 1, p - 1);
s := copy(s, p + 1, maxint);
Self.Color := StringToColor(s);
Application.ProcessMessages;
canvas.draw(10, 10, bm); // z.B.
end;