Date: 02-16-2022
Return to Index
created by gbSnippets
'Memory Object on the clipboard can be in any data format
'There are pre-defined clipboard formats
Clipboard Viewer Chain
SetClipboardViewer
GetClipboardViewer
WM_DrawClipboard
ChangeClipboardChain
WM_ChangeCBChain
AddClipboardFormatListener
CountClipboardFormats
GetClipboardFormatName
GetClipboardSequenceNumber
GetUpdatedClipboardFormats
RemoveClipboardFormatListener
Custom Formats
RegisterClipboardFormat
Open/Close Clipboard
OpenClipboard
GetOpenClipboardWindow which Window has the Clipboard Open
GetClipboardOwner which Window owns the Clipboard
CloseClipboard
Getting Data
EnumClipboardFormat retrieve All available formats
GetPriorityClipboardFormat identify the best available format
IsClipboardFormatAvailable ask If specific format Is available
GetClipboardData Return Handle To Memory Global Object containing Data in the specified format
Ownership
EmptyClipboard Clear Content And takes ownership
? Delayed Rendering???
SetClipboardData %Null?
WM_RenderFormat
WM_RenderAllFormats
Memory And The Clipboard
A Memory Object that Is To be placed On the Clipboard should be
allocated by Using the GlobalAlloc Function With the GMEM_MOVEABLE flag.
WM_CLEAR
WM_COPY
WM_CUT
WM_PASTE
WM_ASKCBFORMATNAME
WM_CHANGECBCHAIN
WM_CLIPBOARDUPDATE
WM_DESTROYCLIPBOARD
WM_DRAWCLIPBOARD
WM_HSCROLLCLIPBOARD
WM_PAINTCLIPBOARD
WM_RENDERALLFORMATS
WM_RENDERFORMAT
WM_SIZECLIPBOARD
WM_VSCROLLCLIPBOARD
METAFILEPICT
CF_BITMAP Handle To a Bitmap (HBITMAP).
CF_DIB Memory Object containing a BITMAPINFO structure followed by the Bitmap bits.
CF_DIBV5
CF_DIF
CF_DSPBITMAP
CF_DSPENHMETAFILE
CF_DSPMETAFILEPICT
CF_DSPTEXT
CF_ENHMETAFILE
CF_GDIOBJFIRST
CF_GDIOBJLAST
CF_HDROP
CF_LOCALE
CF_METAFILEPICT
CF_OEMTEXT
CF_OWNERDISPLAY
CF_PALETTE
CF_PENDATA
CF_PRIVATEFIRST
WM_DESTROYCLIPBOARD message.
CF_PRIVATELAST
CF_RIFF
CF_SYLK
CF_TEXT
CF_TIFF
CF_UNICODETEXT
CF_WAVE
'Jose Examples:
Result = gAfxGetClipboardText(%CF_Text|%CF_OEMText|%CF_UnicodeText)
Function AfxGetClipboardTextA(cFormat as Dword) As String
Local hMem As Dword, pMem As AsciiZ Ptr
If IsTrue IsClipboardFormatAvailable(cFormat) Then ' // If the text format is available...
If IsTrue OpenClipboard(0) Then ' // Opens the clipboard
hMem = GetClipboardData(%cFormat) ' // Gets memory object of clipboard text
If hMem Then
pMem = GlobalLock(hMem) ' // Locks it and get a pointer
If pMem Then Function = @pMem ' // Assigns the data to our function return value
GlobalUnlock hMem ' // Releases the memory object
End If
CloseClipboard ' // Closes the clipboard
End If
End If
End Function
Result = gAfxSetClipboardText(%CF_Text|%CF_OEMText|%CF_UnicodeText, TextIn As String)
Function gAfxSetClipboardText (ByVal cFormat as Dword, ByVal TextIn As String) As Dword
Local pMem, hMem, hData As Dword
If IsTrue OpenClipboard(0) Then ' // Opens the clipboard
EmptyClipboard ' // Empties the clipboard
hMem = GlobalAlloc(%GMEM_MOVEABLE Or %GMEM_DDESHARE, (Len(strText) + 1) * IIF(cFormat = %CF_UnicodeText,2,1)) ' // Allocates a global memory block
If hMem Then
pMem = GlobalLock(hMem) ' // Locks it and gets a pointer to the memory location
If cFormat = %CF_UnicodeText Then
If pMem Then Poke$$ pMem, TextIn & $Nul & $Nul ' // Copies the text into the allocated memory block
Else
If pMem Then Poke$ pMem, TextIn & $Nul ' // Copies the text into the allocated memory block
End If
GlobalUnlock hMem ' // Unlocks the memory block
hData = SetClipboardData(cFormat, hMem) ' // Places the text in the clipboard
If IsTrue hData Then
Function = hData ' // Returns the handle of the data
Else
GlobalFree hMem ' // Frees the memory block
End If
End If
CloseClipboard ' // Closes the clipboard
End If
End Function
http://www.garybeene.com/sw/gbsnippets.htm