You need to put in the clipboard a few files.
-
- User
- Posts: 74
- Joined: Fri Jun 29, 2012 4:50 pm
You need to put in the clipboard a few files.
How to put in the clipboard a few files? Looking examples, but there in the clipboard copy only one file. If several files divide symbol NULL, will not work, although in Delphi it works.
Thank you in advance
Thank you in advance
Re: You need to put in the clipboard a few files.
Code: Select all
Procedure FilesCreateMem(Array files.s(1))
Protected i, j, size, *mem, *pmem
j = ArraySize(files())
For i = 0 To j
If Right(files(i), 1) = "\" : files(i) = Left(files(i), Len(files(i)) - 1) : EndIf
size + StringByteLength(files(i)) + 1 * SizeOf(Character)
Next
size + 1 * SizeOf(Character)
*mem = AllocateMemory(size)
If *mem
*pmem = *mem
For i = 0 To j
PokeS(*pmem, files(i))
*pmem + StringByteLength(files(i)) + 1 * SizeOf(Character)
Next
EndIf
ProcedureReturn *mem
EndProcedure
Procedure FilesToClipBoard(Array sources.s(1))
Protected clipFile, hGlobal, *lpGlobal.DROPFILES, *mem
*mem = FilesCreateMem(sources())
If *mem
If OpenClipboard_(0)
EmptyClipboard_()
hGlobal = GlobalAlloc_(#GHND, SizeOf(DROPFILES) + MemorySize(*mem))
If hGlobal
*lpGlobal = GlobalLock_(hGlobal)
ZeroMemory_(*lpGlobal, SizeOf(DROPFILES))
*lpGlobal\pFiles = SizeOf(DROPFILES)
CompilerIf #PB_Compiler_Unicode
*lpGlobal\fWide = 1 ; Unicode
CompilerEndIf
*lpGlobal\fNC = 0
*lpGlobal\pt\x = 0
*lpGlobal\pt\y = 0
CopyMemory_((*lpGlobal + SizeOf(DROPFILES)), *mem, MemorySize(*mem))
GlobalUnlock_(hGlobal)
If SetClipboardData_(#CF_HDROP, hGlobal)
clipFile = #True
EndIf
EndIf
CloseClipboard_()
EndIf
FreeMemory(*mem)
EndIf
ProcedureReturn clipFile
EndProcedure
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
- User
- Posts: 74
- Joined: Fri Jun 29, 2012 4:50 pm
- doctorized
- Addict
- Posts: 882
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
Re: You need to put in the clipboard a few files.
@ ts-soft: What can we do if we want to take the files back from the clipboard?
Re: You need to put in the clipboard a few files.
With a GUI you can use the DragDrop Lib from PB or use this:
Code: Select all
Procedure FilesFromClipBoard(Path.s)
Protected nFiles, cbFiles, buffSize, file$, f
Protected nPath.s
If OpenClipboard_(0)
If IsClipboardFormatAvailable_(#CF_HDROP)
cbFiles = GetClipboardData_(#CF_HDROP)
If cbFiles
nFiles = DragQueryFile_(cbFiles, -1, 0, 0)
For f = 0 To nFiles - 1
buffSize = DragQueryFile_(cbFiles, f, 0, 0) + 1
file$ = Space(buffSize)
DragQueryFile_(cbFiles, f, @file$, buffSize)
If FileSize(file$) = - 2
nPath = Path + GetFilePart(file$) + "\"
CopyDirectory(file$ + "\", nPath, "", #PB_FileSystem_Recursive)
ElseIf FileSize(file$) > -1
CopyFile(file$, Path + GetFilePart(File$))
EndIf
Next
EndIf
EndIf
CloseClipboard_()
EndIf
ProcedureReturn nFiles
EndProcedure
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: You need to put in the clipboard a few files.
I have try that and nothing works, any TXT and any jpg
And nothing too in the clipboard
And nothing too in the clipboard

Code: Select all
UseJPEGImageDecoder()
Global AppPath.s
AppPath = Space(200)
GetCurrentDirectory_(200, @AppPath)
AppPath = Trim(AppPath)
If Right(AppPath,1) <> "\"
AppPath + "\"
EndIf
Dim TabloFichier.s(2)
; TabloFichier(1) = AppPath + "Fichier1.txt"
; TabloFichier(2) = AppPath + "Fichier2.txt"
TabloFichier(1) = AppPath + "Valerie.jpg"
TabloFichier(2) = AppPath + "Valerie 2.jpg"
Debug FilesToClipBoard(TabloFichier())
Debug FilesFromClipBoard("C:\Temp\")
Debug wrote:1
0

Not a destination
Re: You need to put in the clipboard a few files.
The Code works in a real application from me: http://www.freeware.de/download/jacommander_39825.html
In the moment i have no time to write a example, sry.
In the moment i have no time to write a example, sry.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- doctorized
- Addict
- Posts: 882
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
Re: You need to put in the clipboard a few files.
Thanx a lot my friend!! Works fine for me!!ts-soft wrote:With a GUI you can use the DragDrop Lib from PB or use this

Re: You need to put in the clipboard a few files.
For me FilesFromClipBoard(Path.s) works perfectly...Kwaï chang caïne wrote:I have try that and nothing works, any TXT and any jpg
But i have the same problem, for enter the files in the clipboard, the return is 1 but no file.
Even with the right click/paste of the mouse
Code: Select all
Procedure FilesCreateMem(Array files.s(1))
Protected i, j, size, *mem, *pmem
j = ArraySize(files())
For i = 0 To j
If Right(files(i), 1) = "\" : files(i) = Left(files(i), Len(files(i)) - 1) : EndIf
size + StringByteLength(files(i)) + 1 * SizeOf(Character)
Next
size + 1 * SizeOf(Character)
*mem = AllocateMemory(size)
If *mem
*pmem = *mem
For i = 0 To j
PokeS(*pmem, files(i))
*pmem + StringByteLength(files(i)) + 1 * SizeOf(Character)
Next
EndIf
ProcedureReturn *mem
EndProcedure
Procedure FilesToClipBoard(Array sources.s(1))
Protected clipFile, hGlobal, *lpGlobal.DROPFILES, *mem
*mem = FilesCreateMem(sources())
If *mem
If OpenClipboard_(0)
EmptyClipboard_()
hGlobal = GlobalAlloc_(#GHND, SizeOf(DROPFILES) + MemorySize(*mem))
If hGlobal
*lpGlobal = GlobalLock_(hGlobal)
ZeroMemory_(*lpGlobal, SizeOf(DROPFILES))
*lpGlobal\pFiles = SizeOf(DROPFILES)
CompilerIf #PB_Compiler_Unicode
*lpGlobal\fWide = 1 ; Unicode
CompilerEndIf
*lpGlobal\fNC = 0
*lpGlobal\pt\x = 0
*lpGlobal\pt\y = 0
CopyMemory_((*lpGlobal + SizeOf(DROPFILES)), *mem, MemorySize(*mem))
GlobalUnlock_(hGlobal)
If SetClipboardData_(#CF_HDROP, hGlobal)
clipFile = #True
EndIf
EndIf
CloseClipboard_()
EndIf
FreeMemory(*mem)
EndIf
ProcedureReturn clipFile
EndProcedure
Dim arrayfile.s(2)
arrayfile(1) = "C:\file1.txt"
arrayfile(2) = "C:\file1.xls"
Debug FilesToClipBoard(arrayfile())
Sorry but, Google translate is my friend 

Re: You need to put in the clipboard a few files.
A array begins with 0!
Code: Select all
Dim arrayfile.s(1)
arrayfile(0) = "C:\file1.txt"
arrayfile(1) = "C:\file1.xls"
Debug FilesToClipBoard(arrayfile())
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: You need to put in the clipboard a few files.
ooops !!A array begins with 0!

Works great now, thanks for your help and sharing..
Sorry but, Google translate is my friend 
