Re: Pasting files from the clipboard
From: Alex Ivanov (consul_at_collegeclub.com)
Date: 04/19/04
- Next message: Ralph: "Re: Shell function - accessing an Access secure db (.MDW file)"
- Previous message: Jim Carlock: "Re: VB6 - VB.NET post SP6"
- In reply to: Jim Deutch: "Re: Pasting files from the clipboard"
- Messages sorted by: [ date ] [ thread ]
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 > >
- Next message: Ralph: "Re: Shell function - accessing an Access secure db (.MDW file)"
- Previous message: Jim Carlock: "Re: VB6 - VB.NET post SP6"
- In reply to: Jim Deutch: "Re: Pasting files from the clipboard"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|