第一个问题的原因找到了,只能修改源程:
implementation
var
PixPerInch: TPoint;
procedure TfrOLEView.Draw(Canvas: TCanvas);
var
Bmp: TBitmap;
function HimetricToPixels(const P: TPoint): TPoint;
begin
Result.X := MulDiv(P.X, PixPerInch.X, 2540);
Result.Y := MulDiv(P.Y, PixPerInch.Y, 2540);
end;
procedure DrawOLE;
var
S: TPoint;
R: TRect;
liViewSize: TPoint;
begin
with OleContainerdo
begin
if SizeMode <> smStretch then
begin
OleObjectInterface.GetExtent(DVASPECT_CONTENT, liViewSize);
S := HimetricToPixels(liViewSize);
if SizeMode = smScale then
begin
if dx * S.Y > dy * S.X then
begin
S.X := S.X * dy div S.Y;
S.Y := dy;
end
else
begin
S.Y := S.Y * dx div S.X;
S.X := dx;
end;
end;
if (SizeMode = smCenter) or (SizeMode = smScale) then
begin
R.Left := DRect.Left + (dx - S.X) div 2;
R.Top := DRect.Top + (dy - S.Y) div 2;
R.Right := R.Left + S.X;
R.Bottom := R.Top + S.Y;
end
else
if SizeMode = smClip then
begin
SetRect(R, DRect.Left, DRect.Top, DRect.Left + S.X, DRect.Top + S.Y);
IntersectClipRect(Canvas.Handle, DRect.Left, DRect.Top, DRect.Right, DRect.Bottom);
end;
if R.Left < DRect.Left then
R.Left := DRect.Left;
if R.Top < DRect.Top then
R.Top := DRect.Top;
if R.Right > DRect.Right then
R.Right := DRect.Right;
if R.Bottom > DRect.Bottom then
R.Bottom := DRect.Bottom;
end
else
SetRect(R, DRect.Left, DRect.Top, DRect.Right, DRect.Bottom);
OleDraw(OleContainer.OleObjectInterface, DVASPECT_CONTENT, Canvas.Handle, R);
end;
end;
begin
begin
Draw(Canvas);
CalcGaps;
OleContainer.Width := dx;
OleContainer.Height := dy;
with Canvasdo
begin
ShowBackground;
if (dx > 0) and (dy > 0) then
begin
with OleContainerdo
begin
if OleObjectInterface <> nil then
DrawOLE
// OleDraw(OleObjectInterface, DVASPECT_CONTENT, Canvas.Handle, DRect)
procedure Initialize;
var
DC: HDC;
begin
DC := GetDC(0);
PixPerInch.X := GetDeviceCaps(DC, LOGPIXELSX);
PixPerInch.Y := GetDeviceCaps(DC, LOGPIXELSY);
ReleaseDC(0, DC);
end;
initialization
Initialize;