 |
BCX Console Demonstration Program S71.bas
|
' --------------------------------------------------------
' Clip by Kevin Diggins (C) 2000
' Copies a text file to the Windows clipboard
' --------------------------------------------------------
DIM
Fsize '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 Translator ³"
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 Translator ³"
PRINT
"ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
COLOR
4
, 0
PRINT
" "
, Fsize, " bytes sent to the clipboard!"
COLOR
7
, 0
'---------------------------------------------------------------------------
SUB
SetClipBoard (
Text$)
LOCAL
nd AS
HANDLE
LOCAL
ns$ AS
LPSTR
nd =
GlobalAlloc(
GHND, LEN
(
Text$)
+
1
)
ns =
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
Read AS
DWORD
DIM
H AS
HANDLE
H =
CreateFile(
Fname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0
, 0
)
;
ReadFile(
H, Buffer$, Count, &
Read, NULL)
CloseHandle(
H)
END
SUB