不通过InsertObjectDialog,插入一个文件到RichEdit里面,这个问题我研究了很久,最后
采用的方式是剪贴板拷贝、粘贴 [
],另外还有一种方式比较复杂,通过组织RichEdit格
式的文本进行添加,比如下面的函数,将Bitmap转化为一个RichEdit格式的字符串
function BitmapToRTF(pict: TBitmap): string;
var
bi,bb,rtf: string;
bis,bbs: Cardinal;
achar: ShortString;
hexpict: string;
I: Integer;
begin
GetDIBSizes(pict.Handle,bis,bbs);
SetLength(bi,bis);
SetLength(bb,bbs);
GetDIB(pict.Handle,pict.Palette,PChar(bi)^,PChar(bb)^);
rtf := '{/rtf1 {/pict/dibitmap ';
SetLength(hexpict,(Length(bb) + Length(bi)) * 2);
I := 2;
for bis := 1 to Length(bi) do
begin
achar := Format('%x',[Integer(bi[bis])]);
if Length(achar) = 1 then
achar := '0' + achar;
hexpict[I-1] := achar[1];
hexpict
:= achar[2];
Inc(I,2);
end;
for bbs := 1 to Length(bb) do
begin
achar := Format('%x',[Integer(bb[bbs])]);
if Length(achar) = 1 then
achar := '0' + achar;
hexpict[I-1] := achar[1];
hexpict := achar[2];
Inc(I,2);
end;
rtf := rtf + hexpict + ' }}';
Result := rtf;
end;