BCX Console Demonstration Program s71.bas
|
' --------------------------------------------------------
' Clip by Kevin Diggins (C) 2000
' Copies a text file to the Windows clipboard
' --------------------------------------------------------
DIM OrigCodePage%
OrigCodePage% = GetConsoleOutputCP()
SetConsoleOutputCP(437)
DIM Fsize AS LONGLONG 'Size of file in bytes
DIM Test 'Test if the filename EXIST's
DIM FilName$
CLS
IF COMMAND$ = "" THEN
PRINT "������������������������������������������������������?
PRINT "?Clip! A Win32 command line clipboard utility ?
PRINT "?Usage: Clip! Filename ( LongFileNames Allowed) ?
PRINT "?Copy any text file to the Windows clipboard FAST! ?
PRINT "?Freeware by Kevin Diggins -- created using BCX! ?
PRINT "? BCX - The free BASIC to C ?
PRINT "������������������������������������������������������?
END
END IF
FilName$ = COMMAND$
Test = EXIST(FilName$) ' Does it exist?
IF Test = 0 THEN ' Nope ...
PRINT "File Not Found"
END ' Exit stage left
END IF
Fsize = LOF(FilName$) 'How big is the file?
DIM Buffer$ * Fsize + 10 'Create a buffer at least that big
Buffer$ = "" 'initialize it
GetFile(FilName$, Buffer$, Fsize)
SetClipBoard(Buffer$) 'Place it on the clipboard
FREE Buffer$ 'release allocated memory back to Windows
PRINT "������������������������������������������������������?
PRINT "?Clip! A Win32 command line clipboard utility ?
PRINT "?Usage: Clip! Filename ( LongFileNames Allowed) ?
PRINT "?Copy any text file to the Windows clipboard FAST! ?
PRINT "?Freeware by Kevin Diggins -- created using BCX! ?
PRINT "? BCX - The free BASIC to C ?
PRINT "������������������������������������������������������?
COLOR 4, 0
PRINT " ", Fsize, " bytes sent to the clipboard!"
COLOR 7, 0
PAUSE
SetConsoleOutputCP(OrigCodePage)
'---------------------------------------------------------------------------
SUB SetClipBoard (Text$)
LOCAL nd AS HANDLE
LOCAL ns$ AS LPSTR
nd = GlobalAlloc(GHND, LEN(Text$) + 1)
ns = (LPSTR)GlobalLock(nd)
ns$ = Text$
GlobalUnlock(nd)
OpenClipboard(0)
EmptyClipboard()
SetClipboardData(CF_TEXT, nd)
CloseClipboard()
END SUB
SUB GetFile (Fname$, Buffer$, Count)
' ------------------------------------------------------
' Assumes a valid Filename to a file that exists
' and a Buffer large enough to hold Count bytes
' -------------------------------------------------------
DIM dwRead AS DWORD
DIM H AS HANDLE
H = CreateFile(Fname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
ReadFile(H, Buffer$, Count, &dwRead, NULL)
CloseHandle(H)
END SUB
Result:
Result not displayed for this example.