Class XbpClipBoard() Foundation
Class function of the XbpClipBoard class.
The XbpClipBoard class provides objects that access the clipboard. The clipboard allows data to be easily exchanged between different processes.
Managing the clipboard is similar to managing a file. Both must be opened before reading or writing information and must later be closed. The unique aspect of the clipboard is that only one single process (more precisely: one single thread) at a time can access the clipboard. This is similar to a file being exclusively opened. As long as the Xbase++ application has the clipboard open, no other application or thread can access it. It is therefore extremely important to close the clipboard after it has been opened by an XbpClipBoard object.
The clipboard can simultaneously hold information that appears in different formats. For example, ASCII text can be stored in the clipboard along with a graphic in the metafile format. Access to different formats in the clipboard is controlled using the :getBuffer() method of the XbpClipBoard object. The formats that are currently available in the clipboard are determined using the :queryFormats() method. The following constants are defined in the XBP.CH file to identify the different clipboard formats:
Constant | Description |
---|---|
XBPCLPBRD_TEXT | Data in ASCII text format |
XBPCLPBRD_BITMAP | Graphic data in a bitmap format |
XBPCLPBRD_METAFILE | Graphic data in a meta file format |
nFormat | User-defined format, see :registerFormat() |
// This example demonstrates how data from the clipboard can
// be imported into an Xbase++ application. An MLE is created
// that receives the data. A text editor is started to
// write data to the clipboard (write, mark, and copy text
// to the clipboard using Ctrl+Insert). SetTimerEvent() is
// used to start a thread that controls the clipboard. When
// characters in the editor are copied to the clipboard, they
// are imported into the edit buffer of the MLE in the
// function MonitorClipBoard(). Later the data in the clipboard
// is deleted.
#include "Xbp.ch"
#include "Appevent.ch"
PROCEDURE Main
LOCAL nEvent, mp1, mp2, oXbp
LOCAL cText, oMle, oClipBoard
SetColor("N/W")
CLS
SetAppWindow():useShortCuts := .T.
// Create MLE
oMle := XbpMLE():new():create( , , {50,50}, {550,300} )
// Create clipboard object
oClipBoard := XbpClipBoard():new():create()
// Create thread for controlling the clipboard
SetTimerEvent( 100, {|| MonitorClipBoard( oClipBoard, oMle ) } )
#ifdef __OS2__
// Editor E.EXE starten
RunShell('START "Editor called by Xbase++" /F E.EXE')
#else
// Editor Notepad.EXE starten
RunShell('START "Editor called by Xbase++" Notepad.EXE')
#endif
// Event loop
nEvent := 0
DO WHILE nEvent <> xbeP_Close
nEvent := AppEvent( @mp1, @mp2, @oXbp )
oXbp:HandleEvent( nEvent, mp1, mp2 )
ENDDO
RETURN
**********************************************
PROCEDURE MonitorClipBoard( oClipBoard, oMLE )
LOCAL cText, aFormats
// Open clipboard and determine the data formats
// contained in it
oClipBoard:open()
aFormats := oClipBoard:queryFormats()
// If text is available in the clipboard, import the
// text into the MLE and delete data in the clipboard
IF AScan( aFormats, XBPCLPBRD_TEXT ) > 0
cText := oClipBoard:getBuffer( XBPCLPBRD_TEXT )
oClipBoard:clear()
oMLE:setData( cText )
Tone(500)
ENDIF
oClipBoard:close()
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.