Results 1 to 5 of 5

Thread: Image in clipboard

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Posts
    14

    Question

    How is it possible to inserting an image to the clipboard.
    There is no clipboard.setimage og so...
    _________________
    .-{= TwoFace =}-.

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344
    if you can simulate the "Print Screen" key, that automatically puts a image of the screen in the clipboard, sort of like a screen capture.
    -RaY
    VB .Net 2010 (Ultimate)

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Posts
    14

    yeah

    Yeah, but that dont help me, as i need to put an image from a picturebox to the clipboard...
    _________________
    .-{= TwoFace =}-.

  4. #4
    Guest
    Try this:

    Code:
    'Compatibility: VB 6,VB 5,VB 4/32
    
    'Task: Copy the entire contents of a PictureBox to the clipboard
    
    
    'Declarations
    ' #VBIDEUtils#************************************************************
    ' * Programmer Name  : Waty Thierry
    ' * Web Site         : http://www.geocities.com/ResearchTriangle/6311/
    ' * E-Mail           : [email protected]
    ' * Date             : 7/10/98
    ' * Time             : 16:59
    ' * Module Name      : Clipboard_Module
    ' * Module Filename  : Clipboard.bas
    ' **********************************************************************
    ' * Comments         : Clipboard functions
    ' *
    ' *
    ' **********************************************************************
    
    Option Explicit
    
    ' General functions:
    Private Type RECT
       Left     As Long
       Top      As Long
       Right    As Long
       Bottom   As Long
    End Type
    
    ' GDI functions:
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal
    X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
    ByVal hSrcDC As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop
    As Long) As Long
    Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
    
    ' Creates a memory DC
    Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As
    Long
    
    ' Creates a bitmap in memory:
    Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long,
    ByVal nWidth As Long, ByVal nHeight As Long) As Long
    
    ' Places a GDI Object into DC, returning the previous one:
    Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal
    hObject As Long) As Long
    
    ' Deletes a GDI Object:
    Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    
    ' Clipboard functions:
    Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long)
    As Long
    Private Declare Function CloseClipboard Lib "user32" () As Long
    Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As
    Long, ByVal hMem As Long) As Long
    Private Declare Function GetClipboardFormatName Lib "user32" Alias
    "GetClipboardFormatNameA" (ByVal wFormat As Long, ByVal lpString As
    String, ByVal nMaxCount As Long) As Long
    Private Declare Function EmptyClipboard Lib "user32" () As Long
    Private Declare Function CountClipboardFormats Lib "user32" () As Long
    Private Declare Function EnumClipboardFormats Lib "user32" (ByVal wFormat
    As Long) As Long
    Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal
    wFormat As Long) As Long
    Private Declare Function RegisterClipboardFormat Lib "user32" Alias
    "RegisterClipboardFormatA" (ByVal lpString As String) As Long
    Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As
    Long) As Long
    
    ' Memory functions:
    Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As
    Long
    Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long)
    As Long
    Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As
    Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
    (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
    
    Public Enum EPredefinedClipboardFormatConstants
       [_First] = 1
       CF_TEXT = 1
       CF_BITMAP = 2
       CF_METAFILEPICT = 3
       CF_SYLK = 4
       CF_DIF = 5
       CF_TIFF = 6
       CF_OEMTEXT = 7
       CF_DIB = 8
       CF_PALETTE = 9
       CF_PENDATA = 10
       CF_RIFF = 11
       CF_WAVE = 12
       CF_UNICODETEXT = 13
       CF_ENHMETAFILE = 14
       CF_HDROP = 15
       CF_LOCALE = 16
       CF_MAX = 17
       [_Last] = 17
    End Enum
    
    
    'Code:
    Public Function CopyEntirePictureToClipboard(ByRef objFrom As Object) As
    Boolean
       '
    #VBIDEUtils#************************************************************
       ' * Programmer Name  : Waty Thierry
       ' * Web Site         : http://www.geocities.com/ResearchTriangle/6311/
       ' * E-Mail           : [email protected]
       ' * Date             : 7/10/98
       ' * Time             : 16:59
       ' * Module Name      : Clipboard_Module
       ' * Module Filename  : Clipboard.bas
       ' * Procedure Name   : CopyEntirePictureToClipboard
       ' * Parameters       :
       ' *                    ByRef objFrom As Object
       '
    **********************************************************************
       ' * Comments         : Copy the entire contents of a PictureBox to the
    clipboard
       ' *
       ' *
       '
    **********************************************************************
    
       Dim lhDC       As Long
       Dim lhBmp      As Long
       Dim lhBmpOld   As Long
    
       ' Create a DC compatible with the object we're copying
       ' from:
       lhDC = CreateCompatibleDC(objFrom.hdc)
       If (lhDC <> 0) Then
          ' Create a bitmap compatible with the object we're
          ' copying from:
          lhBmp = CreateCompatibleBitmap(objFrom.hdc, objFrom.ScaleWidth \
    Screen.TwipsPerPixelX, objFrom.ScaleHeight \ Screen.TwipsPerPixelY)
          If (lhBmp <> 0) Then
             ' Select the bitmap into the DC we have created,
             ' and store the old bitmap that was there:
             lhBmpOld = SelectObject(lhDC, lhBmp)
    
             ' Copy the contents of objFrom to the bitmap:
             BitBlt lhDC, 0, 0, objFrom.ScaleWidth \ Screen.TwipsPerPixelX,
    objFrom.ScaleHeight \ Screen.TwipsPerPixelY, objFrom.hdc, 0, 0, SRCCOPY
    
             ' Remove the bitmap from the DC:
             SelectObject lhDC, lhBmpOld
    
             ' Now set the clipboard to the bitmap:
             EmptyClipboard
             OpenClipboard 0
             SetClipboardData CF_BITMAP, lhBmp
             CloseClipboard
    
             ' We don't delete the Bitmap here - it is now owned
             ' by the clipboard and Windows will delete it for us
             ' when the clipboard changes or the program exits.
          End If
    
          ' Clear up the device context we created:
          DeleteObject lhDC
    
          CopyEntirePictureToClipboard = True
    
       Else
          CopyEntirePictureToClipboard = False
    
       End If
    
    End Function

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Posts
    14

    Red face

    Thanks, but how do I use this code?

    CopyEntirePictureToClipboard (Picture1.Picture) does not work!
    _________________
    .-{= TwoFace =}-.

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