Board index » cppbuilder » MetafileCanvas Problems

MetafileCanvas Problems

Hello.  I have to write an app that will combine several metafiles.
Currently I allow the user to choose the files (I put them in a listbox)
and then I display them (using stretchdraw) to a paintbox.  They display
fine, they print fine, but then, I try to output them to a new metafile
and that is where I am having a problem.  When I create a
TMetafileCanvas to draw to, the resulting Metafile is too small.

The original metafiles are about 11 X 16 (inches).

The new one is about 4 X 6.  The constructor takes a tmetafile and an
HDC.  The help says that the constructor sets the size if it needs to be
(see quote)   I suspect that I am passing the wrong HDC, but am unsure
what should be passed.  Since I am initializing the Metafile, the Width
and Height should not be set during construction (see code)

TMetaFileCanvas sets the size of the TMetafile object from the HDC
passed as ReferenceDevice if it does not already have the MMHeight and
MMWidth properties set.

Below is some sample code:

    TMetafile *MyMetafile = new TMetafile;
    int Width, Height;
    Width = MyMetafile->MMWidth;
    Height = MyMetafile->MMHeight;
    TMetafileCanvas *MyMetafileCanvas = new TMetafileCanvas(MyMetafile,
    MyMetafile->MMWidth = Width;
    MyMetafile->MMHeight = Height;
    TRect MyRect;
    MyRect.Left = 0;
    MyRect.Top = 0;
    for(int ii =0;ii < ListBox1->Items->Count;ii++)
        MyRect.Right = MyPicture->Width;
        MyRect.Bottom = MyPicture->Height;
        MyMetafileCanvas->StretchDraw(MyRect, MyPicture);
    delete MyMetafileCanvas;
    MyMetafile->MMWidth = Width;
    MyMetafile->MMHeight = Height;

Thanks to all who answer.


Re:MetafileCanvas Problems

Ronald Sawyer <> wrote in message

>Below is some sample code:

>    TMetafile *MyMetafile = new TMetafile;
>    MyMetafile->LoadFromFile(ListBox1->Items->Strings[0].c_str());
>    int Width, Height;
>    Width = MyMetafile->MMWidth;
>    Height = MyMetafile->MMHeight;
>    TMetafileCanvas *MyMetafileCanvas = new TMetafileCanvas(MyMetafile,
>    MyMetafile->MMWidth = Width;
>    MyMetafile->MMHeight = Height;

  If you check the source, this isn't much help.  Rather be sure to set the
MMWidth and MMHeight properties BEFORE MetafileCanvas creation, and you will get
a Metafile of the correct dimensions.  Otherwise these properties are set by the
DC you pass (PaintBox1->Canvas->Handle in this case).  Also, don't use "Width"
and "Height", but rather "width" and "height", since the caps make it appear to
be referring to the form in which this code appears (if any).  Perhaps the
scoping rules protects from this, but it could be confusing to others.

Your problem, though, may be with the Clipping Region applied to your metafile.
When you create the TMetafileCanvas, the clipping region is set according to
either: a) the MMWidth and MMHeight properties; or b) the Reference DC passed.
I don't remember which at the moment.  I do know, however, that I had troubles
whenever I tried to work with a metafile larger than the reference DC.  The
reason was improper use of Windows graphics; you should use clipping regions to
show the user the viewable region only.  The metafile is then actually larger
than the reference DC, but you only see the part within the Clipping rectangle.
I did not run into this until I tested my app on an NT machine.

For more help, look in the Win32 help under clipping regions and possibly in
DejaNews under things like region, clipping, ClipRect, etc.

Hope that helps!! :)

Joshua D. Bush -0-0-0-0-0-0-0-0-0-0-0-0-0-0-0- The Scarlet Pumpkin

Other Threads