home *** CD-ROM | disk | FTP | other *** search
- Listing 1
-
- Private Sub Command1_Click()
- On Error Resume Next
-
- 'Create the raw metafile
- fl$ = "c:\temp\test.tmr"
- Meta = CreateMetafile(ByVal fl$)
-
- 'Set metafile co-ordinates
- e = SetMapMode(Meta, 8)
- e = SetWindowOrg(Meta, 0, 800)
- e = SetWindowExt(Meta, 800, -800)
- 'Definitive Office 97 cure: place the origin top left
- 'e = SetWindowOrg(Meta, 0, 0)
- 'e = SetWindowExt(Meta, 800, 800)
-
- 'Select null brush and black pen
- Brush = GetStockObject(5)
- Pen = GetStockObject(7)
- e = SelectObject(Meta, Pen)
- e = SelectObject(Meta, Brush)
-
- 'Box Method 1: Draw box using lines
- 'Causes box to disappear when converted to drawing objects in Office 97
- 'unless co-ordinates reset as above
- e = MoveTo(Meta, 200, 200)
- e = LineTo(Meta, 600, 200)
- e = LineTo(Meta, 600, 600)
- e = LineTo(Meta, 200, 600)
- e = LineTo(Meta, 200, 200)
- 'Box Method 1b: cross the box
- 'OK in Office 97
- 'e = LineTo(Meta, 600, 600)
-
- 'Box Method 2: Draw box using rectangle API call
- 'Sometimes OK in Office 97 - does NOT always work in more complex drawings!
- 'e = Rectangle(Meta, 200, 200, 600, 600)
-
- 'Box Method 3: Draw box using polygon API call
- 'OK in Office 97
- 'ReDim pt(4) As POINTAPI
- 'pt(0).x = 200
- 'pt(0).y = 200
- 'pt(1).x = 200
- 'pt(1).y = 600
- 'pt(2).x = 600
- 'pt(2).y = 600
- 'pt(3).x = 600
- 'pt(3).y = 200
- 'pt(4).x = 200
- 'pt(4).y = 200
- 'e = Polygon(Meta, pt(0), 5)
-
- 'Draw right hand tail and whiskers
- e = MoveTo(Meta, 600, 400)
- e = LineTo(Meta, 700, 400)
- e = MoveTo(Meta, 700, 600)
- e = LineTo(Meta, 700, 200)
-
- 'Draw left hand tail and whiskers
- e = MoveTo(Meta, 200, 400)
- e = LineTo(Meta, 100, 400)
- e = MoveTo(Meta, 100, 600)
- e = LineTo(Meta, 100, 200)
-
- 'Clean up resources and close metafile
- e = DeleteObject(Pen)
- e = DeleteObject(Brush)
- e = DeleteMetaFile(CloseMetafile(Meta))
-
- 'Make placeable header
- With MFHDR
- .Key = &H9AC6CDD7
- .Handle = 0
- .Inch = 210
- .Resvd = 0
- End With
- With MFHDR.bbox
- .l = 0
- .t = 0
- .r = metaw%
- .b = metah%
- End With
-
- p$ = "c:\temp\testok.wmf"
- Kill p$
- Hout = FreeFile
- Open p$ For Binary As #Hout
- Put #Hout, , MFHDR
-
- 'Create and write the checksum
- Get #Hout, 1, XO
- For c = 0 To 9
- s = s Xor XO.XorInt(c)
- Next
- MFHDR.XSum = s
- Put #Hout, 1, MFHDR
-
- 'Allow for WMF > 64K
- Hin = FreeFile
- Open fl$ For Binary As #Hin
- d$ = Space$(16384)
- For Chunk = 1 To LOF(Hin) \ 16384
- Get #Hin, , d$
- Put #Hout, , d$
- Next
- d$ = Space$(LOF(Hin) Mod 16384)
- Get #Hin, , d$
- Put #Hout, , d$
- Close #Hin
- Close #Hout
-
- End Sub
-