You need to put in the clipboard a few files.

Just starting out? Need help? Post your questions and find answers here.
NikitaOdnorob98
User
User
Posts: 74
Joined: Fri Jun 29, 2012 4:50 pm

You need to put in the clipboard a few files.

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post 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
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.
Image
NikitaOdnorob98
User
User
Posts: 74
Joined: Fri Jun 29, 2012 4:50 pm

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

Post by NikitaOdnorob98 »

Thanks!
User avatar
doctorized
Addict
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.

Post by doctorized »

@ ts-soft: What can we do if we want to take the files back from the clipboard?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post 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
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.
Image
User avatar
Kwai chang caine
Always Here
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.

Post 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
ImageThe happiness is a road...
Not a destination
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post 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.
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.
Image
User avatar
doctorized
Addict
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.

Post 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!! :)
TO7
User
User
Posts: 29
Joined: Wed Dec 03, 2008 9:06 am

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

Post 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()) 
Sorry but, Google translate is my friend :-(
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post 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()) 
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.
Image
TO7
User
User
Posts: 29
Joined: Wed Dec 03, 2008 9:06 am

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

Post by TO7 »

A array begins with 0!
ooops !! :oops:
Works great now, thanks for your help and sharing..
Sorry but, Google translate is my friend :-(
Post Reply