Re: Pasting files from the clipboard

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Alex Ivanov (consul_at_collegeclub.com)
Date: 04/19/04


Date: Mon, 19 Apr 2004 09:37:52 -0700

It may be done easier. See an example at
http://www.aleksoft.net/samples/DropFiles.zip

--
Please reply to NG only. The email address is not monitored.
Alex.
"Jim Deutch" <103134.3516@compuserve.com> wrote in message
news:4083f167.12487445@news.compuserve.com...
> On Mon, 19 Apr 2004 15:43:17 +0100, "Michael Cutter"
> <michael@centurai.com> wrote:
>
> >Hi All -
> >
> >As we all know, you can use "Cut and Paste" within the Windows Shell to
move
> >files around.
> >I'm looking for an API or something in VB6 that can perform the "Paste"
part
> >of that process - if I use Explorer to "Copy" the file, can I then have
some
> >code behind a button that can "Paste" the file into another location.
> >At the moment, I've got a ShellExecute call to open explorer with the
> >correct folder displayed, then a SendKeys to send the Ctrl+V, wait a bit
> >then a second Sendkeys to send Alt+F4 and close the window.
> >Surely there is a more elegant solution than that??!
>
> Getting that list of files "copied" from Explorer is not as easy as I
> expected!  Here's a function that'll do it, though, and return a
> string containing a comma-delimited list of file names.
>
> It's probably not bullet-proof: hasn't been tested in NT, and it
> ignores the DROPFILES .Offset (assumes it'll always be = 20): since
> they've provided a value there, ya gotta be suspicious that it could
> change... It's also got a hardcoded limit of 1024 characters, which
> you can change, but it'll still be a hardcoded limit.
>
> Anyway, I got this far and you can take it wherever you want to go
> (today...) <g>
>
> Jim Deutch
>
> Private Type DROPFILES
>     Offset As Long
>     x As Long
>     y As Long
>     flag As Long
>     wide As Long
>     files As String * 1024
> End Type
>
> Private Declare Function CloseClipboard% Lib "user32" ()
> Private Declare Function OpenClipboard% Lib "user32" (ByVal hwnd%)
> Private Declare Function GetClipboardData& Lib "user32" (ByVal wFormat
> As Long)
> Private Declare Function EnumClipboardFormats& Lib "user32" (ByVal
> wFormat As Long)
> Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory"
> (Destination As Any, Source As Any, ByVal Length As Long)
> Private Declare Function GlobalLock& Lib "kernel32" (ByVal hMem As
> Long)
> Private Declare Function GlobalUnlock& Lib "kernel32" (ByVal hMem As
> Long)
>
>
> Function GetClipboardFileList() As String
>     Dim retval As Long
>     Dim h As Long
>     Dim h2 As Long
>     Dim bFound As Boolean
>     Dim DropInfo As DROPFILES
>     Dim i As Long
>     Dim nStop As Long
>     Dim TwoZeros As String
>     Dim OneZero As String
>     Const CF_HDROP = 15
>
>     TwoZeros = Chr$(0) & Chr$(0)
>     OneZero = Chr$(0)
>     retval = 0
>     'find out if there are filenames on the clipboard
>     If OpenClipboard(Form1.hwnd) Then
>         Do
>             retval = EnumClipboardFormats(retval)
>             If retval = CF_HDROP Then
>                 bFound = True
>             End If
>         Loop While retval
>         retval = CloseClipboard()
>     End If
>
>     If bFound Then
>         If OpenClipboard(Form1.hwnd) Then
>             'get the handle to the data
>             h = GetClipboardData(CF_HDROP)
>             'resolve the pointer
>             h2 = GlobalLock(h)
>             'copy the DROPFILES structure
>             CopyMem DropInfo, ByVal h2, Len(DropInfo)
>             'cleanup
>             retval = GlobalUnlock(h)
>             retval = CloseClipboard()
>
>             For i = 1 To 1024
>                 'find the end of the list of files
>                 If Mid$(DropInfo.files, i, 2) = TwoZeros Then
>                     nStop = i - 1
>                     Exit For
>                 End If
>                 'change from null-delimited to comma-delimited
>                 If Mid$(DropInfo.files, i, 1) = OneZero Then
>                     Mid$(DropInfo.files, i, 1) = ","
>                 End If
>             Next i
>         End If
>     End If
>
>     If nStop Then
>         GetClipboardFileList = Left$(DropInfo.files, nStop)
>     Else
>         GetClipboardFileList = vbNullString
>     End If
>
> End Function
>
>


Relevant Pages

  • Re: Alpha search to load a list box
    ... Dim strTemp As String ... Private Sub LblAlpha_MouseDown(Button As Integer, Shift As Integer, X ... Dim StartX As Long, WidthX As Long ... Private Declare Function apiSelectObject Lib "gdi32" Alias ...
    (microsoft.public.access.formscoding)
  • Re: Alpha search to load a list box
    ... Dim strTemp As String ... Private Declare Function apiSelectObject Lib "gdi32" Alias ... Dim newfont As Long ' Handle to our Font Object we created. ...
    (microsoft.public.access.formscoding)
  • Re: CryptAPI
    ... > Private Declare Function CryptAcquireContext Lib "advapi32.dll" Alias ... > As String, ByVal dwProvType As Long, ByVal dwFlags As Long) As Long ... > On Error GoTo ErrSign ...
    (microsoft.public.vb.winapi)
  • Re: Shellexecute in VB6
    ... Dim Serial_Port_Initialized As Boolean ... Private Declare Function OpenProcess Lib "kernel32" _ ... (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As ...
    (microsoft.public.vb.general.discussion)
  • ListView.SelectedItem cannot be modified
    ... Dim objFind As LV_FINDINFO ... Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd ... lpClassName As String, ByVal lpWindowName As String) As Long ... 'CompareDates: This is the sorting routine that gets passed to the ...
    (microsoft.public.vb.controls)