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

Send file to clipboard

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

  • Send file to clipboard

    Code:
      'Write a file to the Windows 95+ clipboard
      'DOS programs can SHELL "FILENAME"
    
      $COMPILE EXE
      $DIM ALL
      $INCLUDE "WIN32API.INC"
    
    FUNCTION WriteToClipBoard(BYVAL content AS STRING) AS LONG
      ON ERROR GOTO WriteToClipBoardError
      LOCAL where AS LONG, hData AS LONG, bytes AS LONG
      content = content + CHR$(0)
      bytes = LEN(content)
      IF bytes < 2 THEN EXIT FUNCTION
      hData = GlobalAlloc(&H2002, bytes)    ' get memory of clipboard
      where = GlobalLock(hData)             ' lock it
      POKE$ where, content                  ' paste text into memory
      GlobalUnlock hData                    ' unlock memory
      IF ISFALSE OpenClipboard(0) THEN      ' if clipboard isn't available
        GlobalFree hData                    ' free up memory
        FUNCTION = 0
        EXIT FUNCTION
       END IF
      EmptyClipboard                          ' empty whatever's in there now
      SetClipBoardData %CF_TEXT, hData        ' %CF_TEXT = for text
      CloseClipboard                          ' release clipboard
      FUNCTION = -1                           ' success
    WriteToClipBoardExit:
    EXIT FUNCTION
    
    WriteToClipBoardError:
      RESUME WriteToClipBoardExit
    END FUNCTION
    
    FUNCTION PBMAIN() AS LONG
      ON ERROR GOTO PbMainError
      DIM LineNum AS LONG
      DIM FILNAME AS STRING
      DIM Content AS STRING
      DIM Ecode AS LONG
      FilName$ = COMMAND$
    
      LineNum = 10:FilName$ = COMMAND$
      IF DIR$(FilName$) = "" THEN EXIT FUNCTION
      LineNum = 20:OPEN FilName$ FOR BINARY SHARED AS #1
      LineNum = 30:GET$ #1, LOF(1), content$
      lineNum = 40: REPLACE CHR$(0) WITH CHR$(32) IN content$ 'replace nulls
      LineNum = 50:Ecode& = WriteToClipBoard(content$ + CHR$(0))
      LineNum = 60
      CLOSE #1
    PbMainExit:
    EXIT FUNCTION
    PbMainError:
    MSGBOX "Error writing to clipboard at line "+STR$(LineNum)+ "Error number"+STR$(ERR)
    RESUME PbMainExit
    END FUNCTION



    -------------
    mailto:[email protected]
    The world is full of apathy, but who cares?
Working...
X