EnumEnhMetaFile Help Needed! (Please Please Please) 
Author Message
 EnumEnhMetaFile Help Needed! (Please Please Please)

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



Fri, 06 Dec 2002 03:00:00 GMT  
 EnumEnhMetaFile Help Needed! (Please Please Please)
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



Fri, 06 Dec 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

2. Can anyone HELP me PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE

3. Please, Please, Please I need help working with dates

4. Please, Please, Please I need your help with Winsock

5. HELP NEEDED PLEASE PLEASE PLEASE!!!!

6. PLEASE HELP PLEASE HELP PLEASE HELP

7. Please Please help !!! Crystal Report Help Needed

8. Design Help PLEASE PLEASE PLEASE!

9. Please Please PLEASE HELP!!!!!

10. URGENT HELP PLEASE PLEASE PLEASE???

11. Please please please, help me :-)

12. Please, please, please help!!

 

 
Powered by phpBB® Forum Software