我自己也拷贝别人的一个组件,可是只能显示一种bmp格式符号,源码如下
unit Unit2;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, Mo23ASymbol_TLB, StdVcl;
type
TMo23AsMaker = class(TAutoObject, IMo23AsMaker)
protected
function Draw(hDC, x, y: Integer): HResult;
stdcall;
function ResetDC(hDC: Integer): HResult;
stdcall;
function SetupDC(hDC: Integer;
dpi:do
uble;
const pBaseSym: IDispatch): HResult;
stdcall;
function SetBitMapName2(var BitMapName: WideString): WideString;
safecall;
end;
implementation
uses
Windows, ComServ, Graphics, Classes;
var
FBitmapFileName: string;
intSize : LongInt;
bmpBitmap : TBitmap;
function TMo23AsMaker.Draw(hDC, x, y: Integer): HResult;
var
cnvCanvas : TCanvas;
begin
cnvCanvas := TCanvas.Create;
cnvCanvas.Handle := hDC;
cnvCanvas.Brush.Style := bsClear;
cnvCanvas.BrushCopy( Rect( X - intSize, Y - intSize, X + intSize, Y +intSize ),
bmpBitmap, Rect( 0, 0, bmpBitmap.Width,bmpBitmap.Height ), clWhite );
cnvCanvas.Free;
Result := 0;
end;
function TMo23AsMaker.ResetDC(hDC: Integer): HResult;
begin
bmpBitmap.Free;
Result := 0;
end;
function TMo23AsMaker.SetupDC(hDC: Integer;
dpi:do
uble;
const pBaseSym: IDispatch): HResult;
begin
intSize := Variant( pBaseSym ).Size;
bmpBitmap := TBitmap.Create;
//bmpBitmap.LoadFromResourceName( Hinstance, 'MS_HOUSE' );
bmpBitmap.LoadFromFile(FBitmapFileName);
Result := 0;
end;
function TMo23AsMaker.SetBitMapName2(
var BitMapName: WideString): WideString;
begin
FBitmapFileName:=BitMapName;
Result := FBitmapFileName;
end;
initialization
TAutoObjectFactory.Create(ComServer, TMo23AsMaker, Class_Mo23AsMaker,
ciMultiInstance, tmApartment);
end.