Author Topic: Clipboard Writing and Reading  (Read 2296 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Clipboard Writing and Reading
« on: May 24, 2011, 06:52:39 PM »

This required a few additions to minwin.inc.

I follow the MS example code very closely but strip out all the C complexity.

MS Clipboard:
http://msdn.microsoft.com/en-us/library/ms648709(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/ms649016(v=vs.85).aspx


Code: [Select]
  '=============
  'THE CLIPBOARD
  '=============

  #include "..\..\inc\minwin.inc"



  '--------------------
  'WRITING TO CLIPBOARD
  '====================


  'Get exclusive access to the clipboard
  '=====================================

  OpenClipboard 0 'hwnd


  'Get some data
  '=============

  s="text for the clipboard"
  le=1+len s
 
  'Allocate a global memory object for the text.
  '=============================================
 
  h = GlobalAlloc GMEM_MOVEABLE, le

  'Lock the handle.
  '================
 
  k = GlobalLock h


  'copy in the data
  '================

  'copy k, *s, le
  zstring z at k : z=s

  'Attach it to the clipboard
  '==========================

  SetClipboardData CF_TEXT, h

  'Unlock the memory block
  '=======================
 
  GlobalUnlock h

  'Release the Clipboard
  '=====================

  CloseClipboard 0 'hwnd



  '----------------------
  'READING FROM CLIPBOARD
  '======================


  'Get exclusive access to the clipboard
  '=====================================

  OpenClipboard 0 'hwnd

  'get data from clipboard
  '=========================

  h = GetClipboardData CF_TEXT

  'Lock the handle.
  '================
 
  k = GlobalLock h

  'Copy it
  '=======

  zstring z at k : string s=z

  'Unlock the memory block
  '=======================
 
  GlobalUnlock h

  'Release the Clipboard
  '=====================

  CloseClipboard 0 'hwnd

  'Display data
  '============

  print s
 


Charles