Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Save drawing to Clipboard as a metafile?
Message
From
07/03/2001 22:23:22
 
 
To
07/03/2001 08:58:56
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00482650
Message ID:
00482988
Views:
8
>How do I save my drawing using Pset and Line methods to the Windows clipboard as a Windows metafile. VB5 only seems to provide a command to do this as a bitmap. Robert Davey

Create a form with two picture controls picSource, and PicCopy set autoredraw true. 2 command buttons cmdClear, cmdCopy. Draw in picSource with your mouse and you can copy it via metascript into picCopy. You can see exactly how the script is written.
Option Explicit

Private Drawing As Boolean
Private PointX() As Single
Private PointY() As Single
Private NumPoints As Integer

Private Declare Function CreateMetaFile Lib "gdi32" Alias "CreateMetaFileA" (ByVal lpString As Any) As Long
Private Declare Function CloseMetaFile Lib "gdi32" (ByVal hMF As Long) As Long
Private Declare Function PlayMetaFile Lib "gdi32" (ByVal hdc As Long, ByVal hMF As Long) As Long
Private Declare Function DeleteMetaFile Lib "gdi32" (ByVal hMF As Long) As Long

Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Any) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

' Create a memory metafile and play it back into
' the destination picture boxes.
Private Sub cmdCopy_Click()
Dim i As Integer
Dim mDC As Long
Dim hMF As Long
Dim status As Long
Dim x As Single
Dim y As Single

    ' Create the memory metafile.
    mDC = CreateMetaFile(ByVal 0&)
    If mDC = 0 Then
        MsgBox "Error creating the metafile.", vbExclamation
        Exit Sub
    End If

    ' Draw in the metafile.
    For i = 1 To NumPoints
        x = PointX(i)
        y = PointY(i)
        If x < 0 Then
            MoveToEx mDC, -x, y, ByVal 0&
        Else
            LineTo mDC, x, y
        End If
    Next i

    ' Close the metafile.
    hMF = CloseMetaFile(mDC)
    If hMF = 0 Then
        MsgBox "Error closing the metafile.", vbExclamation
    Else
        ' Play the metafile.
            picCopy.Cls
            If PlayMetaFile(picCopy.hdc, hMF) = 0 Then
                MsgBox "Error playing the metafile.", vbExclamation
            End If
            picCopy.Refresh
    End If

    ' Delete the metafile.
    If DeleteMetaFile(hMF) = 0 Then
        MsgBox "Error deleting the metafile.", vbExclamation
    End If
End Sub

' Start drawing.
Private Sub picSource_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    Drawing = True
    AddPoint -x, y
End Sub
' Add a point to the list of points.
Private Sub AddPoint(ByVal x As Single, ByVal y As Single)
    ' Add the new point.
    NumPoints = NumPoints + 1
    ReDim Preserve PointX(1 To NumPoints)
    ReDim Preserve PointY(1 To NumPoints)
    PointX(NumPoints) = x
    PointY(NumPoints) = y

    ' This represents the start of a new segment.
    If x < 0 Then
        picSource.CurrentX = -x
        picSource.CurrentY = y
    Else
        picSource.Line -(x, y)
    End If
End Sub

' Continue drawing.
Private Sub picSource_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    ' Do nothing if we are not drawing.
    If Not Drawing Then Exit Sub

    ' Add the point.
    AddPoint x, y
End Sub

' Stop drawing.
Private Sub picSource_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    Drawing = False
End Sub
' Clear the form.
Private Sub cmdClear_Click()
    picSource.Cls
    NumPoints = 0
End Sub


Private Sub mnuFileExit_Click()
    Unload Me
End Sub
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Previous
Next
Reply
Map
View

Click here to load this message in the networking platform