unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, RichEdit, ExtDlgs, ComCtrls, ExtCtrls, ActiveX, ComObj, re_bmp, ClipBrd;
type
TForm1 = class(TForm)
Image1: TImage;
RichEdit1: TRichEdit;
OpenPictureDialog1: TOpenPictureDialog;
Button1: TButton;
Button2: TButton;
RichEdit2: TRichEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
InsertBitmapToRE(RichEdit1.Handle, Image1.Picture.Bitmap.Handle);
end;
end;
Function MAP_LOGHIM_TO_PIX(Const Val: Integer; Const Log: Integer): Integer;
Const
HIMETRIC_PER_INCH=2540;
Begin
Result:=MulDiv(Val, Log, HIMETRIC_PER_INCH);
End;
Function MAP_LOGHIMPT_TO_PT(Const Val: TPoint; Const Handle: HWND = 0): TPoint;
Var
DC: HDC;
Begin
DC:=GetDC(Handle);
Result.X:=MAP_LOGHIM_TO_PIX(Val.X, GetDeviceCaps(DC, LOGPIXELSX));
Result.Y:=MAP_LOGHIM_TO_PIX(Val.Y, GetDeviceCaps(DC, LOGPIXELSY));
ReleaseDC(Handle, DC);
End;
procedure TForm1.Button2Click(Sender: TObject);
Var
IREO: IRichEditOle;
OleClientSite: IOleClientSite;
ReObject: TReObject;
I: Integer;
ViewObject2: IViewObject2;
Rc: TRect;
bmp:TBitmap;
Pt: TPoint;
begin
RichEdit2.Text := '';
SendMessage(RichEdit1.Handle, EM_GETOLEINTERFACE, 0, Longint(@IREO));
IREO.GetClientSite(OleClientSite);
For I:= 0 to IREO.GetObjectCount-1 Do
Begin
ZeroMemory(@ReObject, SizeOf(ReObject));
ReObject.cbStruct:=SizeOf(ReObject);
If Succeeded(IREO.GetObject(I, ReObject, $00000001)) Then
If Succeeded(ReObject.poleobj.QueryInterface(IViewObject2, ViewObject2)) Then
Begin
ViewObject2.GetExtent(DVASPECT_CONTENT, -1, Nil, Pt);
Pt:=MAP_LOGHIMPT_TO_PT(Pt, RichEdit1.Handle);
bmp:=TBitmap.Create;
Bmp.Height := Pt.Y;
Bmp.Width := Pt.X;
SetRect(Rc, 0, 0, Bmp.Width, Bmp.Height);
OleDraw(ReObject.poleobj, DVASPECT_CONTENT, bmp.Canvas.Handle, Rc);
InsertBitmapToRE(RichEdit2.Handle, bmp.Handle);
End
Else
ShowMessage('Error: Can''t get IViewObject2');
End;
end;
end.