EnumEnhMetaFile Help Needed! (Please Please Please)

EnumEnhMetaFile Help Needed! (Please Please Please)

Post by Mike Carls » Tue, 20 Jun 2000 04:00:00



Hi,

     I need to step through an EMF file so I can make some changes to it as
it plays.  I've managed to get it almost working but now I've hit a little
snag.  Here's some code (I hope the line wraps don't mess it all up):

Public Function EnhMetaFileProc(ByVal ClientHDC As Long, ByRef HandTab As    
        HANDLETABLE, ByRef MetaRec As ENHMETARECORD, ByVal nHandles As Long,    
        ByVal OptData As Long) As Integer

Dim Pen As Long

    If (MetaRec.iType = 38) Then
          ' I want to do stuff when Create Pen is to be played
        ' The following three lines kind of work but eventually
        ' (after redrawing about 4 or 5 times) I get an out of
        ' memory error.  Since I have a lot of free RAM I'm
        ' assuming I hit a 64k barrier.

        'Pen = CreatePen(1, 1, RGB(0, 0, 255))
        'SelectObject ClientHDC, Pen
        'DeleteObject Pen
          x = 1
    Else
        x = PlayEnhMetaFileRecord(ClientHDC, HandTab, MetaRec, ByVal
nHandles)
    End If

    EnhMetaFileProc = x
End Function

Public Sub EnumEMF(EMFHandle As Long, EMFObj As PictureBox)
Dim picRECT As RECT

    GetClientRect EMFObj.hwnd, picRECT
    x = EnumEnhMetaFile(ByVal EMFObj.hdc, ByVal EMFHandle, AddressOf
EnhMetaFileProc, 0, picRECT)
End Sub

---

     The subroutine (EnumEMF) gets called from a form and passes the handle
to the EMF (that I got when loading the file with GetEnhMetaFile) and the
picturebox that I want to play the EMF into.  This all goes to
EnumEnhMetaFile which eventually calls EnhMetaFileProc.  This is where I
get stuck.  If I just send everything to PlayEnhMetaFileRecord everything
works great.  If I try to make any changes (see the function for a little
explanation) I run out of memory.  The CreatePen call is just one thing I
need to check for so I need a solution for basically changing any of the
records I want.

     If someone could let me know where I've went wrong and point me to an
example of the "right" way to do this I would really appreciate it. :)  
I've searched all over the net and all I've been able to find is one old
piece of code for WMF (it's similar but I still couldn't get it working)
and the API man page (looks like this would be fairly easy in C++ but I
can't use that in this project).

     Thanks in advance,

     Mike

 
 
 

EnumEnhMetaFile Help Needed! (Please Please Please)

Post by Neal Andrew » Tue, 20 Jun 2000 04:00:00


Hi Mike

When you place your pen in the hdc you are not storing the old pen and
placing it back into the hdc when you have finished with it. Not too sure
how metafiles store there objects, but I presume that somewhere in the
metafile it tries to delete the object that you have removed from the dc
when you selected the new pen into the hdc, and this is coursing the memory
error. Could be quite tricky keeping track of which pens are in the dc and
if and when they are deleted. Try storing the old handle to the pen and
replace it back when you have finished with your substitute pen.

i.e.
hOldPen=SelectObject(ClientHDC, Pen)

when you've finished drawing
hCustomPen=SelectObject(ClientHDC, hOldPen)

Assert to see if the pen you replaced earlier is the same one
debug.assert hCustomPen <> Pen 'hPen and hCustomPen should be the same
handle

then....

 DeleteObject Pen


Quote:

> Hi,

>      I need to step through an EMF file so I can make some changes to it
as
> it plays.  I've managed to get it almost working but now I've hit a little
> snag.  Here's some code (I hope the line wraps don't mess it all up):

> Public Function EnhMetaFileProc(ByVal ClientHDC As Long, ByRef HandTab As
> HANDLETABLE, ByRef MetaRec As ENHMETARECORD, ByVal nHandles As Long,
> ByVal OptData As Long) As Integer

> Dim Pen As Long

>     If (MetaRec.iType = 38) Then
>       ' I want to do stuff when Create Pen is to be played
>         ' The following three lines kind of work but eventually
>         ' (after redrawing about 4 or 5 times) I get an out of
>         ' memory error.  Since I have a lot of free RAM I'm
>         ' assuming I hit a 64k barrier.

>         'Pen = CreatePen(1, 1, RGB(0, 0, 255))
>         'SelectObject ClientHDC, Pen
>         'DeleteObject Pen
>       x = 1
>     Else
>         x = PlayEnhMetaFileRecord(ClientHDC, HandTab, MetaRec, ByVal
> nHandles)
>     End If

>     EnhMetaFileProc = x
> End Function

> Public Sub EnumEMF(EMFHandle As Long, EMFObj As PictureBox)
> Dim picRECT As RECT

>     GetClientRect EMFObj.hwnd, picRECT
>     x = EnumEnhMetaFile(ByVal EMFObj.hdc, ByVal EMFHandle, AddressOf
> EnhMetaFileProc, 0, picRECT)
> End Sub

> ---

>      The subroutine (EnumEMF) gets called from a form and passes the
handle
> to the EMF (that I got when loading the file with GetEnhMetaFile) and the
> picturebox that I want to play the EMF into.  This all goes to
> EnumEnhMetaFile which eventually calls EnhMetaFileProc.  This is where I
> get stuck.  If I just send everything to PlayEnhMetaFileRecord everything
> works great.  If I try to make any changes (see the function for a little
> explanation) I run out of memory.  The CreatePen call is just one thing I
> need to check for so I need a solution for basically changing any of the
> records I want.

>      If someone could let me know where I've went wrong and point me to an
> example of the "right" way to do this I would really appreciate it. :)
> I've searched all over the net and all I've been able to find is one old
> piece of code for WMF (it's similar but I still couldn't get it working)
> and the API man page (looks like this would be fairly easy in C++ but I
> can't use that in this project).

>      Thanks in advance,

>      Mike


 
 
 

1. PLEASE NEED HELP WITH ALIEN BLACK BOX FILTER -- I BEG -- PLEASE PLEASE

Ok -- thanks so much just for reading this!!

Please, E-mail me if you can help me with this...  I have the Alien
Black Box and this happens every time I try to use it: it loads  up, I
see the little Alien Black Box filter graphics, but then time glass
icon shows up for about 20 seconds and finally --  photoshop has
encountered an error making me close it.

Thanks you so much!!

Brian

2. *** SpotLights on 3Dup.com - (November 15, 1999) ***

3. PLEASE PLEASE PLEASE HELP ME!

4. Service urgently required

5. HELP! Mixed-model Colormap setting PLEASE PLEASE PLEASE

6. Looking for DXF/DWG (3d entities) & .AI file import libraries

7. PLEASE PLEASE PLEASE HELP !!!!!!!!!!!!!

8. Netscape Color problems

9. Please,please,please help, with sugar on top

10. PLEASE HELP HELP HELP PLEASE HELP

11. motorbike DXF please please please

12. Please Please Please