Page 1 of 1

You need to put in the clipboard a few files.

Posted: Thu Oct 04, 2012 6:26 pm
by NikitaOdnorob98
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

Re: You need to put in the clipboard a few files.

Posted: Thu Oct 04, 2012 6:44 pm
by ts-soft

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

Re: You need to put in the clipboard a few files.

Posted: Thu Oct 04, 2012 6:52 pm
by NikitaOdnorob98
Thanks!

Re: You need to put in the clipboard a few files.

Posted: Fri Oct 05, 2012 9:16 am
by doctorized
@ 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.

Posted: Fri Oct 05, 2012 9:32 am
by ts-soft
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

Re: You need to put in the clipboard a few files.

Posted: Fri Oct 05, 2012 11:14 am
by Kwai chang caine
I have try that and nothing works, any TXT and any jpg
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

Re: You need to put in the clipboard a few files.

Posted: Fri Oct 05, 2012 11:53 am
by ts-soft
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.

Re: You need to put in the clipboard a few files.

Posted: Fri Oct 05, 2012 4:40 pm
by doctorized
ts-soft wrote:With a GUI you can use the DragDrop Lib from PB or use this
Thanx a lot my friend!! Works fine for me!! :)

Re: You need to put in the clipboard a few files.

Posted: Wed Oct 17, 2012 6:23 pm
by TO7
Kwaï chang caïne wrote:I have try that and nothing works, any TXT and any jpg
For me FilesFromClipBoard(Path.s) works perfectly...
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()) 

Re: You need to put in the clipboard a few files.

Posted: Wed Oct 17, 2012 6:32 pm
by ts-soft
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()) 

Re: You need to put in the clipboard a few files.

Posted: Thu Oct 18, 2012 9:08 am
by TO7
A array begins with 0!
ooops !! :oops:
Works great now, thanks for your help and sharing..