Results 1 to 7 of 7

Thread: Copy file into Clipboard

  1. #1

    Thread Starter
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252

    Arrow Copy file into Clipboard

    How do I copy a file using the api into the clipboard, so that i
    can paste ist later into an application? (for example a picture).
    And how can I delete it from the clipboard?

    Thank you!

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Here is an example (not a file):
    Code:
    Const LR_LOADFROMFILE = &H10
    Const IMAGE_BITMAP = 0
    Const IMAGE_ICON = 1
    Const IMAGE_CURSOR = 2
    Const IMAGE_ENHMETAFILE = 3
    Const CF_BITMAP = 2
    Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As Long) As Long
    Private Declare Function CloseClipboard Lib "user32" () As Long
    Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function EmptyClipboard Lib "user32" () As Long
    Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
    Private Sub Form_Load()
    Dim hDC As Long, hBitmap As Long
        'Load the bitmap into the memory
        hBitmap = LoadImage(App.hInstance, "c:\windows\logow.sys", IMAGE_BITMAP, 320, 200, LR_LOADFROMFILE)
        If hBitmap = 0 Then
            MsgBox "There was an error while loading the bitmap"
            Exit Sub
        End If
        'open the clipboard
        OpenClipboard Me.hwnd
        'Clear the clipboard
        EmptyClipboard
        'Put our bitmap onto the clipboard
        SetClipboardData CF_BITMAP, hBitmap
        'Check if there's a bitmap on the clipboard
        If IsClipboardFormatAvailable(CF_BITMAP) = 0 Then
            MsgBox "There was an error while pasting the bitmap to the clipboard!"
        End If
        'Close the clipboard
        CloseClipboard
        'Get the picture from the clipboard
        Me.Picture = Clipboard.GetData(vbCFBitmap)
    End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Oh, and here is the parameter info:
    Code:
    Declare Function SetClipboardData Lib "user32" Alias "SetClipboardDataA" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    
    · uFormat
    Specifies a clipboard format. This parameter can be a registered format or any of the standard clipboard formats listed in the following Remarks section. For information about registered clipboard formats, see the RegisterClipboardFormat function.
    
    · hMem
    Identifies the data in the specified format. This parameter can be NULL, indicating that the window provides data in the specified clipboard format (renders the format) upon request. If a window delays rendering, it must process the WM_RENDERFORMAT and WM_RENDERALLFORMATS messages.
    Once SetClipboardData is called, the system owns the object identified by the hMem parameter. The application can read the data, but must not free the handle or leave it locked. If the hMem parameter identifies a memory object, the object must have been allocated using the GlobalAlloc function with the GMEM_MOVEABLE and GMEM_DDESHARE flags.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4

    Thread Starter
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252
    thank you

  5. #5

    Thread Starter
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252
    But I got a second question. How can I send a paste event to a rich textbox? (probably quite easy).
    Is there a property for that or do I really need to use sendkeys to
    paste something?

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Knowing the hWnd of the RichTextBox is enough to do that.
    All you have to do is to send WM_PASTE message to the RichTextBox.
    Here is the declaration:
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_PASTE = &H302
    Here is the code to do it:
    Code:
    Call SendMessage(RichTextHwnd, WM_PASTE, 0, 0)
    Regards,

  7. #7

    Thread Starter
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252

    Talking

    thanx, that's more professional than using

    RichTextBox1.SetFocus
    SendKeys "^(v)"



    And also it's sure that it works.

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