根据格式名字从剪切板获取数据
function GetDataFromClipboardByFormat(Format: string): string;
var
i, size: Integer;
cfNum: Integer;
cfFmt: Word;
cfName: array [0 .. 1024] of char;
cfData: THandle;
cfMem: Pointer;
begin
Result := '';
if not OpenClipboard(GetActiveWindow) then
Exit;
try
cfNum := CountClipboardFormats;
cfFmt := EnumClipboardFormats(0);
for i := 0 to cfNum - 1 do
begin
GetClipboardFormatName(cfFmt, cfName, 200);
if SameText(cfName, Format) then
begin
cfData := GetClipboardData(cfFmt);
try
cfMem := GlobalLock(cfData);
size := GlobalSize(cfData);
SetLength(Result, size);
Move(cfMem^, Result[1], size);
finally
GlobalUnlock(cfData);
end;
Break;
end;
cfFmt := EnumClipboardFormats(cfFmt);
end;
finally
CloseClipboard;
end;
end;
function GetClipboardAs HTML: string;
var
HTML: string;
index: Integer;
begin
HTML := GetDataFromClipboardByFormat('HTML Format');
HTML := Utf8ToAnsi(HTML);
index := Pos('SourceURL:', HTML);
while (index < Length(HTML)) and (index > 0) and (HTML[index] <> #10) do
Inc(Index);
Inc(index);
Result := Copy(HTML, index, Length(HTML) - index + 1);
end;