'============================================================================== ' ' ** Clipboard ** ' ' Windows encapsulation routines for PB/DLL ' Copyright (c) 1996 by PowerBASIC, Inc. ' ' Note: Assumes that WINAPI.INC will also be included into your code. ' These routines are NOT exportable. They rely on PowerBASIC ' variable types which are not available in other languages. ' '============================================================================== ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' TITLE: Clipboard_GetFormat ' DESC: Returns an integer indicating whether there is an item in the ' Clipboard that matches a specified format. ' SYNTAX: Status% = Clipbard_GetFormat(format) ' 'format' specifies one of the following clipboard formats: ' ' %CF_LINK DDE conversation information ' %CF_TEXT Text ' %CF_BITMAP Bitmap (.BMP file) ' %CF_METAFILE Metafile (.WMF file) ' %CF_DIB Device-independent bitmap ' %CF_PALETTE Color palette ' FUNCTION Clipboard_GetFormat(BYVAL cfFormat AS WORD) AS INTEGER FUNCTION = IsClipboardFormatAvailable(CfFormat) <> 0 END FUNCTION ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' TITLE: Clipboard_Clear ' DESC: Clears the contents of the clipboard. ' SYNTAX: Clipboard_Clear ' SUB Clipboard_Clear () OpenClipboard 0 EmptyClipboard CloseClipboard END SUB ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' TITLE: Clipboard_SetText ' DESC: Puts a text string into the clipboard. ' SYNTAX: Clipboard_SetText Text$ ' SUB Clipboard_SetText(BYVAL Text AS STRING) LOCAL lpMem AS ASCIIZ PTR LOCAL hMem AS WORD ' Allocate global memory block hMem = GlobalAlloc(%GHND, LEN(Text) + 1) ' lock it and get pointer to memory location lpMem = GlobalLock(hMem) ' copy text into memory object @lpMem = Text ' unlock the memory object GlobalUnlock hMem ' add text to the clipboard OpenClipboard 0 EmptyClipboard SetClipboardData %CF_TEXT, hMem CloseClipboard END SUB ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' TITLE: Clipboard_GetText ' DESC: Returns a text string from the clipbard. ' SYNTAX: Text$ = Clipboard_GetText ' FUNCTION Clipboard_GetText() AS STRING LOCAL hMem AS WORD LOCAL lpMem AS ASCIIZ PTR IF Clipboard_GetFormat(%CF_TEXT) THEN ' open the clipboard OpenClipboard 0 ' Get memory object of clipboard text hMem = GetClipboardData(%CF_TEXT) ' lock it and get a pointer lpMem = GlobalLock(hMem) ' assign the data to our function return value FUNCTION = @lpMem ' release the memory object GlobalUnlock hMem ' close the clipboard CloseClipboard ELSE FUNCTION = "" END IF END FUNCTION ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' TITLE: Clipboard_SetData ' DESC: Puts a data object into the clipboard. ' SYNTAX: Clipboard_SetData hData, Format ' NOTES: The application must not use the hData handle once it has called the ' Clipboard_SetData procedure. ' SUB Clipboard_SetData(BYVAL hData AS WORD, BYVAL cfFormat AS INTEGER) ' add data to the clipboard OpenClipboard 0 EmptyClipboard SetClipboardData cfFormat, hData CloseClipboard END SUB ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' TITLE: Clipboard_GetData ' DESC: Get a data object from the clipboard. ' SYNTAX: hData = Clipboard_GetData(format) ' 'format' specifies one of the following clipboard formats: ' ' %CF_BITMAP Bitmap (.BMP file) ' %CF_METAFILE Metafile (.WMF file) ' %CF_DIB Device-independent bitmap ' %CF_PALETTE Color palette ' FUNCTION Clipboard_GetData(BYVAL cfFormat AS WORD) AS WORD LOCAL hSource AS WORD LOCAL hDest AS WORD LOCAL hSize AS DWORD LOCAL lpSource AS DWORD LOCAL lpDest AS DWORD ' add data to the clipboard OpenClipboard 0 hSource = GetClipboardData(cfFormat) CloseClipboard ' Get size of data object hSize = GlobalSize(hSource) ' allocate a new data object hDest = GlobalAlloc(%GHND, hSize) ' get pointers to source and destination objects lpSource = GlobalLock(hSource) lpDest = GlobalLock(hDest) ' copy the data from the source to the destination hmemcpy lpDest, lpSource, hSize ' unlock both data objects GlobalUnlock hSource GlobalUnlock hDest ' return handle to the new data object FUNCTION = hDest END SUB