I'm trying to write some simple clipboard functionality, and I was wondering how to handle (Playback, Save, etc.) CF_WAVE data that is in the clipboard.
Example (Other Formats, not WAVE):
Code: Select all
XIncludeFile "imports.pb" ; For Definition of AddClipboardFormatListener(hWnd) in User32.dll
#WM_CLIPBOARDUPDATE = $031D
Global ClipboardMutex = CreateMutex()
Global WinEvent.l
Procedure CheckClipBoard(*Null)
Shared ClipboardMutex
LockMutex(ClipboardMutex)
Protected Handle = #Null
Protected ReadableData = #False
Protected Format = 0
If OpenClipboard_(#Null)
Repeat
Format = EnumClipboardFormats_( Format )
If Format = #CF_HDROP
ReadableData = #True
Debug "File-List Format!"
Break
ElseIf Format = #CF_TEXT
ReadableData = #True
Debug "Text Format!"
Break
ElseIf Format = #CF_BITMAP
ReadableData = #True
Debug "Image Format!"
UseJPEGImageEncoder()
Break
ElseIf Format = #CF_OEMTEXT
ReadableData = #True
Debug "OEM Text Format!"
Break
ElseIf Format = #CF_UNICODETEXT
ReadableData = #True
Debug "Unicode Text Format!"
Break
ElseIf Format = #CF_WAVE
ReadableData = #True
Debug "WAV Format!"
Break
EndIf
Until Format = 0
If ReadableData
Select Format
Case #CF_HDROP
Handle = GetClipboardData_(#CF_HDROP)
If Handle <> #Null
Define Num_Files = DragQueryFile_(Handle, $FFFFFFFF, 0, 0)
If Num_Files
Define Max_Index = Num_Files - 1 : Define i
Define Buffer.s = Space(#MAX_PATH)
Debug Str(Num_Files) + " Files Were Copied:"
For i = 0 To Max_Index
Define Num_Chars = DragQueryFile_(Handle, i, @Buffer, #MAX_PATH)
If Num_Chars
Define FilePath.s = Trim(Left(Buffer.s, Num_Chars))
If FilePath.s
Debug Str(i+1) + ": " + FilePath
Delay(5)
EndIf
EndIf
Next
Debug "End Of List."
EndIf
EndIf
Case #CF_TEXT
Handle = GetClipboardData_(#CF_TEXT)
Define ClipText.s = PeekS(Handle)
If ClipText <> ""
Debug "Clipboard Text:" + #CRLF$ + ClipText
EndIf
Case #CF_BITMAP
Handle = GetClipboardData_(#CF_BITMAP)
If Handle <> #Null
GetClipboardImage(0)
SaveImage(0, "capture.jpg", #PB_ImagePlugin_JPEG,3) ; As an Example, save the image locally to file 'output.jpg'.
FreeImage(0)
EndIf
Case #CF_OEMTEXT
Handle = GetClipboardData_(#CF_OEMTEXT)
Define String.s = PeekS(Handle,-1,#PB_Ascii)
OemToChar_(@String, @String)
Debug "OEM Text Data:"
Debug String
Case #CF_UNICODETEXT
Handle = GetClipboardData_(#CF_UNICODETEXT)
Define UniString.s = PeekS(Handle,-1,#PB_Unicode)
Debug "Unicode Text:"
Debug UniString
Case #CF_WAVE
; ?
EndSelect
Else
Debug "Error: Unreadable Clipboard Format! (Images / Text / Files supported.)"
EndIf
CloseClipboard_()
Else
Debug "Error: Cannot Open Clipboard!"
EndIf
UnlockMutex(ClipboardMutex)
EndProcedure
Procedure WinCallBack(hwnd, msg, wParam, lParam)
Protected Result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_CLIPBOARDUPDATE
Debug "Clipboard updated!"
CreateThread(@CheckClipBoard(), #Null)
EndSelect
ProcedureReturn Result
EndProcedure
Global MyWin = OpenWindow(#PB_Any, 500, 500, 500, 500, "Clipboard Test")
If MyWin
SetWindowCallback(@WinCallBack(), MyWin)
AddClipboardFormatListener(WindowID(MyWin))
Repeat
WinEvent = WaitWindowEvent()
Delay(1)
Until WinEvent = #PB_Event_CloseWindow
EndIf
End