Reply-To: "Joe C. Hecht" From: "Joe C. Hecht" Newsgroups: borland.public.delphi.graphics References: <9b6q8i$vdd$05$1@news.t-online.com> Subject: Re: Example to access single object in a metafile? Date: Fri, 13 Apr 2001 14:18:28 -0500 Lines: 79 Organization: Joe Hecht Associates X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 24.17.126.157 Message-ID: <3ad750ee$1_1@dnews> X-Trace: dnews 987189486 24.17.126.157 (13 Apr 2001 12:18:06 -0700) Path: dnews Xref: dnews borland.public.delphi.graphics:38020 > Someone has an example how I can access single object in a metafile??? Below is an example of getting metafile information, and enumerating each metafile record... enjoy :) Joe John Kaster is cycling to cure cancer! Lets help him out! http://homepages.borland.com/jkaster/tnt/ function MyEnhMetaFileProc(DC : HDC;// handle to device context lpHTable : PHANDLETABLE; // pointer to metafile handle table lpEMFR : PENHMETARECORD;// pointer to metafile record nObj : integer;// count of objects TheForm : TForm1) : integer; stdcall; begin {draw the metafile record} PlayEnhMetaFileRecord(dc, lpHTable^, lpEMFR^, nObj); {set to zero to stop metafile enumeration} result := 1; end; procedure TForm1.Button1Click(Sender: TObject); var MyMetafile : TMetafile; lpENHMETAHEADER : PENHMETAHEADER; //extra metafile info lpENHMETAHEADERSIZE : DWORD; NumMetaRecords : DWORD; begin {Create a metafile} MyMetafile := TMetafile.Create; with TMetafileCanvas.Create(MyMetafile, 0) do try Brush.Color := clRed; Ellipse(0,0,100,100); Ellipse(100,100,200,200); Ellipse(200,200,300,300); Ellipse(300,300,400,400); Ellipse(400,400,500,500); Ellipse(500,500,600,600); finally Free; end; //we might as well get some extra metafile info lpENHMETAHEADERSIZE := GetEnhMetaFileHeader(MyMetafile.Handle, 0, nil); NumMetaRecords := 0; if (lpENHMETAHEADERSIZE > 0) then begin GetMem(lpENHMETAHEADER, lpENHMETAHEADERSIZE); GetEnhMetaFileHeader(MyMetafile.Handle, lpENHMETAHEADERSIZE, lpENHMETAHEADER); {Here is an exmaple of getting number of metafile records} NumMetaRecords := lpENHMETAHEADER^.nRecords; {enumerate the records} EnumEnhMetaFile(Canvas.Handle, MyMetafile.Handle, @MyEnhMetaFileProc, self, Rect(0, 0, 600, 600)); FreeMem(lpENHMETAHEADER, lpENHMETAHEADERSIZE); end; MyMetafile.Free; end;