'===========================================================================
' Subject: Clipboard Routine                  Date: 06-16-02 (  :  )       
'  Author: Alyce Watson                       Code: liberty                
'  Origin: alycewatson@bigfoot.com          Packet: LIBERTY.ABC
'===========================================================================
'clipboard.bas for Liberty BASIC 3+
'April 2002, Alyce Watson
'alycewatson@bigfoot.com
'
'Demo to get three kinds of data from
'the clipboard and use them in Liberty BASIC 3.
'
'to use this demo, do one of the following:
'
'open notepad, type some text, and choose COPY
'           OR
'open MS Paint, open a picture, then select all
'or part of it and choose COPY
'           OR
'open a wav in sound recorder, then choose COPY
'
'
'if  you have copied text to the clipboard, it will
'appear in the texteditor.
'
'if you have copied an image to the clipboard,
'it will be drawn in the graphicbox
'
'if you have copied a wav, it will play
'

nomainwin
WindowWidth=640:WindowHeight=480
texteditor #1.t, 10,10,300,300
graphicbox #1.g, 320,10,300,300
statictext #1.s, "",10,320,600,50
button #1.b, "Do another!",[again],UL,10,380
open "Clipboard Demo" for window as #1
print #1, "trapclose [quit]"
h=hwnd(#1)

[again]

calldll #user32, "OpenClipboard",h as long, result as long
calldll #user32, "GetClipboardData",_CF_TEXT as long,_
    txt as long

if txt<>0 then
    print #1.t, "!cls"
    print #1.t, "Text content of clipboard:"
    print #1.t, ""
    print #1.t, winstring(txt)
    print #1.t, "!origin 1 1"
end if

calldll #user32, "GetClipboardData",_CF_BITMAP as long,_
    hBmp as long

if hBmp<>0 then
    loadbmp "demo",hBmp
    print #1.g, "cls;down;drawbmp demo 0 0;flush"
end if

calldll #user32, "GetClipboardData",_CF_WAVE as long,_
    hWav as long
if hWav<>0 then
    SND.SYNC = 0
    SND.ASYNC = 1
    SND.NODEFAULT = 2
    SND.MEMORY = 4
    mode=SND.MEMORY or SND.ASYNC OR SND.NODEFAULT
    calldll #winmm, "sndPlaySoundA",_
    hWav as long,mode as long,result as long
end if

calldll #user32, "CloseClipboard", result as void

msg$="Return for CF_TEXT ";txt
msg$=msg$+ chr$(13)+"Return for CF_BITMAP ";hBmp
msg$=msg$+chr$(13)+"Return for  CF_WAVE ";hWav
print #1.s, msg$

wait

[quit]
if hBmp<>0 then unloadbmp "demo"
close #1:end
