It is currently Tue Aug 21, 2018 10:34 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Dealing with CF_WAVE data from clipboard
PostPosted: Fri Mar 09, 2018 10:39 pm 
Offline
User
User

Joined: Wed Apr 02, 2014 12:45 am
Posts: 27
Hi All,

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:
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye