Why EMF file not be displayed?

Just starting out? Need help? Post your questions and find answers here.
goomoo
User
User
Posts: 42
Joined: Sun Dec 05, 2004 9:25 am
Location: China
Contact:

Why EMF file not be displayed?

Post by goomoo »

hello,all!

I'm now reading <Programming Windows> by Charles Petzold and have converted the code snippet about Ehanced Metafile to pb format ,but it doesn't workd, why?

thanks!!

Code: Select all

hwnd.l=OpenWindow(0,0,0,640,480,#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_SystemMenu,"emf test")
;CreateGadgetList(WindowID())

hdcEmf=createEnhMetaFile_(#Null,#Null,#Null,#Null)
Rectangle_(hdcEmf,100,100,200,200)
MoveToEx_(hdcEmf,100,100,#Null)
lineTo_(hdcEmf,200,200)
MoveToEx_(hdcEmf,200,100,#Null)
lineTo_(hdcEmf,100,200)
hemf.l=closeEnhMetafile_(hdcEmf)

quit.l=0
Repeat
  event=WaitWindowEvent()
  If event=#PB_Event_Repaint
    ps.PAINTSTRUCT
    r.RECT
    hdc=BeginPaint_(hwnd,@ps);
    GetclientRect_(hwnd,@r);
    r\left=r\right/4;
    r\right=3*r\right/4;
    r\top=r\bottom/4;
    r\bottom=3*r\bottom/4;
    PlayEnhMetaFile_(hdc,hemf,@rect)
    EndPaint_(hwnd,@ps)
    ;Debug "asdf"
  EndIf 
  If event=#PB_Event_CloseWindow
    DeleteEnhMetaFile_(hemf)
    quit=1
  EndIf
Until quit
Hello, Everyone.
Thanks for your help.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Try this:

Code: Select all

Global hemf

Procedure WndProc(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_SIZE
      RedrawWindow_(hWnd, #NULL, #NULL, #RDW_ERASE|#RDW_INTERNALPAINT|#RDW_INVALIDATE)
    Case #WM_PAINT
      GetClientRect_(hWnd, @r.RECT)
      r\left = r\right/4
      r\right = 3*r\right/4
      r\top = r\bottom/4
      r\bottom = 3*r\bottom/4
      hdc = BeginPaint_(hWnd, @ps.PAINTSTRUCT)
      PlayEnhMetaFile_(hdc, hemf, @r)
      EndPaint_(hWnd, @ps)
  EndSelect
  ProcedureReturn result
EndProcedure

hwnd = OpenWindow(0, 0, 0, 640, 480, #PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_SystemMenu, "emf test")
If hwnd
  hdcEmf = CreateEnhMetaFile_(#NULL, #NULL, #NULL, #NULL)
  If hdcEmf
    Rectangle_(hdcEmf, 100, 100, 200, 200)
    MoveToEx_(hdcEmf, 100, 100, #NULL)
    LineTo_(hdcEmf, 200, 200)
    MoveToEx_(hdcEmf, 200, 100, #NULL)
    LineTo_(hdcEmf, 100, 200)
    hemf = CloseEnhMetaFile_(hdcEmf)
    SetWindowCallback(@WndProc())
    Repeat
      Event=WaitWindowEvent()
      If Event=#PB_Event_CloseWindow
        DeleteEnhMetaFile_(hemf)
        Quit=1
      EndIf
    Until Quit
  EndIf
EndIf
End
El_Choni
goomoo
User
User
Posts: 42
Joined: Sun Dec 05, 2004 9:25 am
Location: China
Contact:

Post by goomoo »

I got it, thank you ,El_Choni !! :D :D
Hello, Everyone.
Thanks for your help.
Post Reply