Sign in to follow this  
Followers 0
Suppir

How to search/replace in clip buffer?

1 post in this topic

#1 ·  Posted (edited)

Hello!

I have some RTF-data in buffer. I can ripoff this data with function written below. But how to do search-replace in this data and put it back into buffer?

func _ClipBoard_GetDataAlternative($Formato = 1)
   If Not (_ClipBoard_IsFormatAvailable($Formato) Or $Formato=18 Or $Formato=19) Then Return SetError(-1, 0, 0)
   If Not _ClipBoard_Open(0) Then Return SetError(-2, 0, 0)
   Switch $Formato
      Case 18
         $iFormat=_ClipBoard_RegisterFormat ("Rich Text Format")
         If $iFormat=0 Then Return SetError(-1, 0, 0)
      Case 19
         $iFormat=_ClipBoard_RegisterFormat ("HTML Format")
         If $iFormat=0 Then Return SetError(-1, 0, 0)
      Case Else
         $iFormat=$Formato
   EndSwitch
   Local $hMemory = _ClipBoard_GetDataEx($iFormat)

   ;_ClipBoard_Close()      ; moved to end: traditionally done *after* copying over the memory

   If $hMemory=0 Then
      _ClipBoard_Close()
      Return SetError(-3, 0, 0)
   EndIf

   Local $pMemoryBlock=_MemGlobalLock($hMemory)

   If $pMemoryBlock=0 Then
      _ClipBoard_Close()
      Return SetError(-4,0,0)
   EndIf

   ; Get the actual memory size of the ClipBoard memory object (in bytes)
   Local $iDataSize=_MemGlobalSize($hMemory)

   If $iDataSize = 0 Then
      _MemGlobalUnlock($hMemory)
      _ClipBoard_Close()
      Return SetError(-5,0,"")
   EndIf

   Local $tData
   Switch $Formato
      Case $CF_TEXT, $CF_OEMTEXT, 18, 19, 20
         $tData = DllStructCreate("char[" & $iDataSize & "]", $pMemoryBlock)
      Case $CF_UNICODETEXT
         ; Round() shouldn't be necessary, as CF_UNICODETEXT should be 2-bytes wide & thus evenly-divisible
         $iDataSize=Round($iDataSize/2)
         $tData = DllStructCreate("wchar[" & $iDataSize & "]", $pMemoryBlock)
      Case Else
         ; Binary data return for all other formats
         $tData = DllStructCreate("byte[" & $iDataSize & "]", $pMemoryBlock)
   EndSwitch
   ; Grab the data from the Structure so the Memory can be unlocked
   Local $vReturn = DllStructGetData($tData, 1)

   ; Unlock the memory & Close the clipboard now that we have grabbed what we needed
   _MemGlobalUnlock($hMemory)
   _ClipBoard_Close()

   ; Return the size of the string or binary object in @extended
   Return SetExtended($iDataSize, $vReturn)
EndFunc   ;==>_ClipBoard_GetData
Edited by Suppir

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0