> Hi.
>
[quoted text clipped - 8 lines]
> Thanks
> Michi
Hi Dave.
> Your question is not clear, when you say "file from the clipboard" do you
> mean that the clipboard contains the data or a reference to the file name?
It doesn't contain any references (as far as I can see).
What I do:
In Excel I do Insert-Object-Create from file, no linking.
Now when I copy this object i can Ctrl-V-paste in within the explorer and
the file will be copied/created.
What I wanna do is to do this paste using code.
But the clipboardformat is not a file (IsClipboardFormatAvailable=15) like
copy a file directly wihtin Explorer, but being an embedded Object
(IsClipboardFormatAvailable=3).
> If it's the former then you can do everything with the Clipboard object
> built into VB6, if you are dealing with actual files then it gets a LOT
> more interesting.
How would this code look like?
Thanks
Michi
Dave O. - 01 Jul 2008 13:35 GMT
> Hi Dave.
>
[quoted text clipped - 23 lines]
> Thanks
> Michi
Declarations (Watch out for line breaks)
Private Const GMEM_MOVEABLE = &H2
Private Const GMEM_ZEROINIT = &H40
Private Const CF_HDROP = 15
Private Const GET_DROP_COUNT = &HFFFFFFFF
Private Const MAX_PATH = 260
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type DROPFILES
pFiles As Long
pt As POINTAPI
fNC As Long
fWide As Long
End Type
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 GlobalAlloc Lib "kernel32" (ByVal wFlags As Long,
ByVal dwBytes As Long) As Long
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 SetClipboardData Lib "user32" (ByVal wFormat As
Long, ByVal hmem As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As
Long) As Long
Private Declare Function DragQueryFile Lib "shell32.dll" Alias
"DragQueryFileA" (ByVal hDrop As Long, ByVal UINT As Long, ByVal lpStr As
String, ByVal ch As Long) As Long
To add a single file to the clipboard this works:
Private Sub FileToClipboard(picFile as String)
' Add a file to the clipboard, this is the easiest way to do it - honestly!
Dim df As DROPFILES
Dim lpGlobal As Long
Dim s As String
Dim r As Long
Dim txtPtr As Long
s = picFile & vbNullChar & vbNullChar
df.pFiles = Len(df)
r = df.pFiles + Len(s)
OpenClipboard Me.hWnd
EmptyClipboard
txtPtr = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, r)
lpGlobal = GlobalLock(txtPtr)
Call CopyMemory(ByVal lpGlobal, df, Len(df))
Call CopyMemory(ByVal (lpGlobal + Len(df)), ByVal s, Len(s))
Call GlobalUnlock(txtPtr)
Call SetClipboardData(15, txtPtr)
CloseClipboard
End Sub
For multiple files a NULL seperated list should do the job
To get the files from the clipboard, this is part of a routine I use to add
the list to a ListView (LV):
Private Function ShowFileList() As Integer
Dim lHandle As Long
Dim strBuffer As String
Dim lCount As Long
Dim s As String
LV.ListItems.Clear
If OpenClipboard(Me.hWnd) > 0 Then
lHandle = GetClipboardData(CF_HDROP)
If Not lHandle = 0 Then
strBuffer = String(MAX_PATH, vbNullChar)
For lCount = 0 To DragQueryFile(lHandle, GET_DROP_COUNT, strBuffer,
Len(strBuffer)) - 1
s = Left$(strBuffer, DragQueryFile(lHandle, lCount, strBuffer,
Len(strBuffer)))
LV.ListItems.Add , , s
Next
End If
This is nowhere near as simple as dealing with text or images in the
clipboard, but should not be too tricky. There are a few unintuitive aspects
and as I have not done much of this sort of thing for years I might not be
as much help as I could be, you may find that now I pointed you in the right
direction you can use Google to get any further instruction you may need.
Regards
Dave O.