Copy to Clipboard?

Blitz3D Forums/Blitz3D Programming/Copy to Clipboard?

Anyone know if it's possible to make Blitz copy a string to the clipboard(Windows Copy/paste buffer)?

; Clipboard Text Read / Write
; ===========================
; Syntax Error & Ed from Mars


; userlibs
; *********************************************
; .lib "user32.dll"
; OpenClipboard%(hwnd%):"OpenClipboard"
; CloseClipboard%():"CloseClipboard"
; ExamineClipboard%(format%):"IsClipboardFormatAvailable"
; EmptyClipboard%():"EmptyClipboard"
; GetClipboardData$(format%):"GetClipboardData"
; SetClipboardData%(format%,txt$):"SetClipboardData"
; *********************************************


Print "Clipboard Test." 
Print "~~~~~~~~~~~~~~~" 
Print "Enter a message for the clipboard." 
Print "Alternatively, leave BLANK to read clipboard." 
a$=Input$(">") 

If a$="" 
	a$=ReadClipboardText$() 
	Print a$
Else 
	WriteClipboardText a$ 
	Print "Text sent to clipboard. Open NotePad and paste!"
EndIf

Print Chr$(13)+"---------------------------------"

a$=Input$("Press RETURN to end ...") 

End

;-----------------------------------

Function WriteClipboardText(txt$)
	Local cb_TEXT=1
	If txt$="" Then Return 
	If OpenClipboard(0)
		EmptyClipboard
		SetClipboardText cb_TEXT,txt$
		CloseClipboard
	EndIf
End Function

;-----------------------------------

Function ReadClipboardText$()
	Local cb_TEXT=1
	Local txt$=""
	If OpenClipboard(0)
		If ExamineClipboard(cb_TEXT) 
			txt$=GetClipboardText$(cb_TEXT)
		EndIf
		CloseClipboard
	EndIf
	Return txt$
End Function


That's cool. Any idea what the arguments are supposed to be for those commands?

Do you mean the hwnd% and format% ?

hwnd% is the Windows handle (not the Blitz handle) for the Blitz program, it isn't necessary to register this though which is why Ed used (0) in his example.

for the format% see this document:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardformats.asp

I got it working, works get! Thanks!