A: Here's the latest version of my (Neil Rubenking) metafile-creation example. I've marked the area where you insert your own drawing code. Note that not *every* GDI function can be used in a metafile DC. I've seen a list of those that cannot; alas, it apparently wasn't in the Windows API Help for the metafile functions.
PS - if you're the puzzling type, try to puzzle out just what this program
draws before you run it. Or at least, figure what the PolyLine method call
draws...
CONST W = 1000; H = 500; R2 = 353;
procedure TForm1.Button1Click(Sender: TObject);
VAR CDC : hDC;
procedure spiral(CV: TCanvas; Colr: TColor; AngInc: Double;
RInc: Integer; Sgn1, Sgn2: Integer);
VAR Theta: Double;
begin
Sgn1 := Sgn1 DIV Abs(Sgn1);
Sgn2 := Sgn2 DIV Abs(Sgn2);
CV.pen.Color := Colr;
Theta := 0;
CV.MoveTo(H,H);
WHILE Theta < pred(H DIV RInc) DO
BEGIN
Theta := Theta + AngInc;
CV.LineTo(H+Sgn1*Round(RInc*Theta*Cos(Sgn2*Theta)),
H+Sgn1*Round(RInc*Theta*Sin(Sgn2*Theta)));
END;
end;
begin
DeleteFile('EXAMPLE.WMF');
WITH TBitmap.Create DO
try
CDC := CreateMetafile(NIL);
Canvas.Handle := CDC;
SetMapMode(Canvas.Handle, MM_ANISOTROPIC);
SetWindowExt(Canvas.Handle, W, W);
WITH Canvas DO
BEGIN
{==== replace
with your own image-creation code ===}
Brush.Color
:= clWhite;
pen.Width :=
10;
pen.Style :=
psInsideFrame;
pen.Color :=
clBlack;
Ellipse(0,0,W,W);
Spiral(Canvas,
clRed, pi/4, 18, 1, 1);
Spiral(Canvas,
clBlue, pi/4, 18, -1, 1);
Pen.Color :=
clBlack;
PolyLine([Point(H,0),
Point(H,H), Point(H-R2, H+R2),
Point(H,H), Point(H,W), Point(H,H),
Point(H+R2,H+R2)]);
{====== end
image-creation code =====}
END;
WITH TMetafile.Create DO
try
Handle := CloseMetafile(CDC);
Inch
:= W;
Height := 128;
Width
:= 128;
SaveToFile('EXAMPLE.WMF');
finally
Free;
end;
finally
Free;
end;
end;