CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2009
    Posts
    8

    [RESOLVED] Trying to paste metafile graphic into a PictureBox with GetData

    Hi,

    I'm trying to paste metafile graphics data into a PictureBox control.

    Code:
    Private Sub mnuEditPaste_Click()
    
        If Not Clipboard.GetFormat(vbCFMetafile) Then
            MsgBox "No metafile data in clipboard"
            Exit Sub
        End If
            
        frmScan.Picture1.Picture = Clipboard.GetData(vbCFMetafile)
        frmScan.Picture1.Refresh
        
    End Sub
    The graphic is pasted and it looks like it is sized so that it would fill the control. However, the bottom of the graphic starts half-way up the control, so that just the bottom half of the graphic is shown in the top half of the control. Anyone know how to fix this, please?

    I'm also trying a different tack, sending the WM_PASTE message to the PictureBox's hwnd but without any success. I asked about this in the thread
    http://www.codeguru.com/forum/showthread.php?t=484849

    Any help much appreciated,

    Graham

  2. #2
    Join Date
    Sep 2009
    Posts
    8

    Re: Trying to paste metafile graphic into a PictureBox with GetData

    More evidence - it could be a problem with OpenOffice.

    I've been having the problem on my development PC which has Open Office on it, not MS Office. When the graphic wasn't displayed properly, it was copied from OpenOffice Calc. I've just tried my executable in another PC which has MS Office on it. I copy the same graphic from the same spreadsheet, but this time using Excel and when I paste it, it does occupy the whole of the PictureBox - i.e. it diplays correctly.

    This doesn't prove that the problem is with OpenOffice - there could be other differences between the PCs. Also, on my development PC, when I pasted the graphic copied from OpenOffice Calc on into Paint, it displayed correctly. So if there is something different about the graphic as it put into the clipboard by OpenOffice to how it is put in by MS Office, Paint can tell the difference and still display the graphic correctly.

  3. #3
    Join Date
    Sep 2009
    Posts
    8

    Re: Trying to paste metafile graphic into a PictureBox with GetData

    Well, I can now paste my graphic in its entirety. You could say I've resolved this, or you could say I've found a work around. I still use GetData, but now I use a temporary Picture object and the PlayMetaFile API function.

    Code:
        Dim picMem As Picture
        Dim hdc As Long
        Dim hmf As Long
        Dim bResult As Long
        Dim strMessage As String
    
        If Not Clipboard.GetFormat(vbCFMetafile) Then
            MsgBox "No metafile data in clipboard"
            Exit Sub
        End If
                   
        Set picMem = Clipboard.GetData(vbCFMetafile)
        
        hmf = picMem.Handle
        hdc = Picture1.hdc
        
        bResult = PlayMetaFile(hdc, hmf)
            
        If bResult = 0 Then
    
            'Our char buffer (to be filled by FormatMessage)
            Dim sErrorMessage As String
            'Initialize the buffer with spaces
            sErrorMessage = String(512, " ")
            FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, 0&, GetLastError(), 0&, sErrorMessage, Len(sErrorMessage), 0&
            MsgBox sErrorMessage
        
        End If
        
        Picture1.Refresh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured