Код:
program Project1;
{$APPTYPE CONSOLE}
uses
Windows;
procedure SetBuffer(Format: Word; var Buffer; Size: Integer);
var
Data: THandle;
DataPtr: Pointer;
begin
OpenClipboard(0);
try
Data := GlobalAlloc(GMEM_MOVEABLE+GMEM_DDESHARE, Size);
try
DataPtr := GlobalLock(Data);
try
Move(Buffer, DataPtr^, Size);
EmptyClipboard;
SetClipboardData(Format, Data);
finally
GlobalUnlock(Data);
end;
except
GlobalFree(Data);
raise;
end;
finally
CloseClipboard;
end;
end;
procedure SetAsText(const Value: string);
begin
SetBuffer(CF_TEXT, PChar(Value)^, Length(Value) + 1);
end;
begin
SetAsText('Hello Clipboard');
Writeln('OK');
Readln;
end.
BOOL OpenClipboard(
HWND hWndNewOwner // handle to window opening clipboard
);
Parameters
hWndNewOwner
Identifies the window to be associated with the open clipboard. If this parameter is NULL, the open clipboard is associated with the current task.