Page 1 of 1

How to use Wmf and Emf

Posted: Tue Dec 17, 2002 6:48 am
by BackupUser
Code updated For 5.20+

Restored from previous forum. Originally posted by Mischa.


Hi!

Code: Select all

Procedure MetaFileDraw(metafile.s,dc,x,y,b,h) 
  If metafile
    WmfRect.RECT
    WmfRect\left=x
    WmfRect\top=y
    WmfRect\right=x+b-1
    WmfRect\bottom=y+h-1
    hmf = GetEnhMetaFile_(metafile)
    If hmf0
      PlayEnhMetaFile_(dc,hmf,WmfRect)
      DeleteEnhMetaFile_(hmf)
    Else
      hmf = GetMetaFile_(metafile)
      If hmf=0
        size=FileSize(metafile)-22
        ReadFile(1,metafile)
        FileSeek(1,22)
        *buffer=AllocateMemory(size,0)
        ReadData(1,*buffer,size)
        CloseFile(1)
      Else
        bytes = GetMetaFileBitsEx_(hmf, bytes,0)
        *buffer=AllocateMemory(bytes,0)
        GetMetaFileBitsEx_(hmf,bytes,*buffer)
      EndIf
      hemf = SetWinMetaFileBits_(size,*buffer,dc,0)
      PlayEnhMetaFile_(dc,hemf,WmfRect)
      DeleteEnhMetaFile_(hemf)
      DeleteMetaFile_(hmf)
    EndIf
  EndIf
EndProcedure

Procedure LoadAndSet()
  metafile.s=OpenFileRequester("Load Metafile", "", "Meta-File|*.wmf;*.emf", 0)
  dc=StartDrawing(ImageOutput(0))
  For k=0 To 250
    c.f+0.5:FrontColor(RGB(100+c,100,255-c))
    Line(0, k, 250, 0)
  Next
  MetaFileDraw(metafile,dc,0,0,250,250)
  StopDrawing()
  StartDrawing(WindowOutput(0))
  DrawImage(ImageID(1), 100, 50)
  StopDrawing()   
EndProcedure


hwnd=OpenWindow(0, 100, 100, 450, 400, "Metafiles", #PB_Window_SystemMenu)
id=CreateImage(1, 250, 250)
ButtonGadget(1, 150, 325, 150, 25, "Load Metafile")


Repeat
  EventID = WaitWindowEvent()
  If EventID = #PB_Event_Gadget
    Select EventGadget()
      Case 1:LoadAndSet()
    EndSelect
  EndIf
Until EventID = #PB_Event_CloseWindow

Mischa

Posted: Tue Dec 17, 2002 2:51 pm
by BackupUser
Restored from previous forum. Originally posted by TerryHough.

Thanks for this tip. I had asked a question about this earlier, but didn't get an answer at that time.

I will study this code and see if I can understand it enough to modify it for my needs.

Keep up the good work!

Terry