Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Copy Filename List to Clipboard for pasting into Explorer and Other Apps...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Copy Filename List to Clipboard for pasting into Explorer and Other Apps...

    Sample use is below. Be sure file(s) exist that are pasted.

    If you build an array of type STRING, and then use the JOIN$ command like this:

    Code:
    LOCAL buffer AS STRING
    
    DIM FileList(1 TO 3) AS STRING
    
    FileList(1)="C:\TEST1.TXT"
    FileList(2)="C:\TEST2.TXT"
    FileList(3)="C:\TEST3.TXT"
    
    buffer = JOIN$(FileList(), $NUL)
    Then passing buffer to the WriteToClipboard function will take care of the rest by appending 2 extra $NUL characters to the end.

    Code:
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "WIN32API.INC"
    
    FUNCTION PBMAIN () AS LONG
    
        CALL WriteToClipboard("C:\TEST.TXT" + $NUL + "C:\ADAMTMP.TXT")
    
    END FUNCTION
    
    SUB WriteToClipboard(inBuf AS STRING)
    
        LOCAL df        AS DROPFILES
        LOCAL tmp       AS STRING * 20
        LOCAL buf       AS STRING
        LOCAL nLen      AS LONG
        LOCAL nGblLen   AS LONG
        LOCAL hGbl      AS LONG
        LOCAL tmpInBuf  AS STRING
        LOCAL lpGlobal  AS LONG
        LOCAL szPtr     AS ASCIIZ PTR
    
        tmpInBuf = inBuf + $NUL + $NUL
    
        df.pFiles = 20
        df.fWide = 0
    
        nLen = LEN(tmpInBuf)
        nGblLen = SIZEOF(df) + nLen
        hGbl = GlobalAlloc(%GHND, nGblLen)
        lpGlobal = GlobalLock(hGbl)
        CopyMemory lpGlobal, VARPTR(df), SIZEOF(df)
        CopyMemory lpGlobal + 20, BYVAL STRPTR(tmpInBuf), BYVAL LEN(tmpInBuf)
        GlobalUnLock hGbl
        IF OpenClipboard(0) THEN
            EmptyClipboard()
            SetClipboardData %CF_HDROP, hGbl
            CloseClipboard()
        END IF
        GlobalFree hGbl 
    
    END SUB
    Adam Drake
    PowerBASIC
Working...
X