
Code:
Declare Function CCSClipboard_GetFormat(ByVal cfFormat As Dword) As Long Declare Function CCSClipboard_SetText(ByVal Text As String) As Long Declare Function CCSClipboard_GetText () As String Declare Function CCSClipboard_SetData (ByVal hData As Dword, ByVal cfFormat As Integer) As Long Declare Function CCSClipboard_GetData(ByVal cfFormat As Dword) As Dword ' ' ' ' '------------------------------------------------------------------------------------------ '==============<CLIPBOARD STUFF>=========================================================== '------------------------------------------------------------------------------------------ Function CCSClipboard_GetFormat Alias "CCSClipboard_GetFormat"(ByVal cfFormat As Dword) Export As Long Function = IsClipboardFormatAvailable(CfFormat) <> 0 End Function '------------------------------------------------------------------------------------------ Function CCSClipboard_SetText Alias "CCSClipboard_SetText"(ByVal Text As String) Export As Long Local lpMem As Asciiz Ptr Local hMem As Dword ' 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 GlobalFree hMem End Function '---------------------------------------------------------------------------------------- Function CCSClipboard_GetText Alias "CCSClipboard_GetText"() Export As String Local hMem As Dword Local lpMem As Asciiz Ptr If CCSClipboard_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 GlobalFree hMem 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. ' Function CCSClipboard_SetData Alias "CCSClipboard_SetData"(ByVal hData As Dword, ByVal cfFormat As Integer) Export As Long ' add data to the clipboard OpenClipboard 0 EmptyClipboard SetClipboardData cfFormat, hData CloseClipboard Function = %TRUE End Function '---------------------------------------------------------------------------------------- ' 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 CCSClipboard_GetData Alias "CCSClipboard_GetData"(ByVal cfFormat As Dword) Export As Dword Local hSource As Dword Local hDest As Dword 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 Function
Scott
Leave a comment: