Clipboard Accsess

BlitzMax Forums/BlitzMax Programming/Clipboard Accsess

This is a very old thread over here. In the meantime there a several new methods for doing this :D

Try this one or look over here

Extern "Win32"
   Function OpenClipboard(hwnd:Int)
   Function CloseClipboard()
   Function EmptyClipboard()
   Function SetClipboardData(format:Int,hMem:Byte Ptr)
   Function GlobalAlloc:Byte Ptr(uflags:Int,bytes:Int)
   Function GlobalFree(buffer:Byte Ptr )
End Extern

?win32
   Const GMEM_FIXED = 0
   Const CF_TEXT=$01

   Function TextToClipboard (txt:String)
      If txt <> ""
         Local CPTR:Byte Ptr = GlobalAlloc(GMEM_FIXED,Len(txt)+1)
         For Local i = 0 Until Len(txt)
            CPTR[i] = txt[i]
         Next
         CPTR[Len(txt)+1]=0
         If OpenClipboard(0)
            EmptyClipboard()
            SetClipboardData (CF_TEXT,CPTR)
            CloseClipboard()
         EndIf
         If CPTR Then GlobalFree (CPTR)
      EndIf
   End Function
?

'rem
TextToClipboard ("HubbaBubba schmeckt scheisse")
'end rem