Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCreate a metafile
Keywordsmetafile, CreateMetaFile, drawing
CategoriesGraphics
 
Use the CreateMetaFile API function to create the file. Draw into it using API functions such as MoveToEx and LineTo. Close the file with CloseMetaFile.

This program's Open button starts a metafile. Then as you scribble on its drawing surface, the program copies your drawing into the file. When you click the button again, the program closes the metafile.

 
Private Sub cmdOpen_Click()
    If cmdOpen.Caption = "Open" Then
        ' Create the metafile.
        MhDC = CreateMetaFile(txtFilename.Text)
        If MhDC = 0 Then
            MsgBox "Error creating metafile."
            Exit Sub
        End If

        picScribble.BackColor = picScribble.BackColor
        picScribble.Visible = True
        cmdOpen.Caption = "Close"
    Else
        ' Close the metafile.
        CloseMetaFile MhDC

        picScribble.Visible = False
        cmdOpen.Caption = "Open"
    End If
End Sub

' Start drawing.
Private Sub picScribble_MouseDown(Button As Integer, Shift _
    As Integer, x As Single, y As Single)
Dim pt As POINTAPI

    If Button And vbLeftButton Then
        Drawing = True
        picScribble.CurrentX = x
        picScribble.CurrentY = y
        MoveToEx MhDC, x, y, pt
    Else
        Drawing = False
    End If
End Sub

' Continue drawing.
Private Sub picScribble_MouseMove(Button As Integer, Shift _
    As Integer, x As Single, y As Single)
    If Drawing Then
        picScribble.Line -(x, y)
        LineTo MhDC, x, y
    End If
End Sub

' Stop drawing.
Private Sub picScribble_MouseUp(Button As Integer, Shift As _
    Integer, x As Single, y As Single)
    Drawing = False
End Sub
 
Open the metafile using some other drawing program such as CorelDRAW! or HiJaak PRO.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated