Wie speichern von Dateien in Clipboard?

3 Antworten

Erstmal ne Lösung für den grundsätzlichen Gebrauch ClipBoard

Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long

Declare Function CloseClipboard Lib "User32" () As Long
Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
Declare Function EmptyClipboard Lib "User32" () As Long
Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Public Const GHND = &H42
Public Const CF_TEXT = 1
'=============  

Public MyDataObject As DataObject

Public Function StoreToClip(Incomming As Variant) ' Any data that is stored in a data element
  Call Modul1.ClipBoard_SetData(Incomming)
End Function

Public Function GetFromClip() As Variant
ClipContent = MyDataObject.GetText(1)
MyDataObject.GetFromClipboard
GetFromClipboard = ClipContent
End Function

Function ClipBoard_SetData(ByVal MyString As String)
Dim hGlobalMemory As Long, lpGlobalMemory As Long
hGlobalMemory = GlobalAlloc(GHND, Strings.Len(MyString) + 1)
lpGlobalMemory = GlobalLock(hGlobalMemory)
lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)
If GlobalUnlock(hGlobalMemory) <> 0 Then
MsgBox "Could not unlock memory location. Copy aborted."
GoTo OutOfHere2
End If
If OpenClipboard(0&) = 0 Then
MsgBox "Could not open the Clipboard. Copy aborted."
Exit Function
End if
 X = EmptyClipboard()
hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
OutOfHere2:
If CloseClipboard() = 0 Then
MsgBox "Could not close Clipboard."
End if
End Function
'===========
Aber bzgl Datei in den Zwischenspeicher bin ich mir über den Zweck nicht sicher. Soll sie abgespielt werden, soll sie per paste woanders hin ?    
Wenn ja, dann gibt es hierfür mit ShellExecute oder den Filesystem Helferlein die richtigen Bibliotheken, um Dateien in den Griff zu kriegen.     

Öhm... also da dir noch niemand geantwortet hat, .... Puh, das ist gar nicht so einfach. Du musst es erst alles einlesen, in Base64 konvertieren, in Chunks zerteilen, und diese dann als specialFormat einfügen.

Aber wenn du Anfänger bist.... willst es nicht lieber etwas langsamer angehen lassen, und es mit etwas einfacherem versuchen?

Lies hier: Beliebige Datenformate in die Zwischenablage kopieren

Zudem zwei Verweise auf die Dokumentation:

Alternativ (und unter Umständen vielleicht auch ratsamer) wäre es eine Lösung, die Datei irgendwo anders abzulegen und nur ihren Pfad in der Zwischenablage zu halten. Das würde allerdings voraussetzen, dass es dein Programm ist, welches den Inhalt aus der Ablage auch wieder empfängt.