Jump to content
Sign in to follow this  

How to search/replace in clip buffer?

Recommended Posts


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
   Local $hMemory = _ClipBoard_GetDataEx($iFormat)

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

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

   Local $pMemoryBlock=_MemGlobalLock($hMemory)

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

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

   If $iDataSize = 0 Then
      Return SetError(-5,0,"")

   Local $tData
   Switch $Formato
      Case $CF_TEXT, $CF_OEMTEXT, 18, 19, 20
         $tData = DllStructCreate("char[" & $iDataSize & "]", $pMemoryBlock)
         ; Round() shouldn't be necessary, as CF_UNICODETEXT should be 2-bytes wide & thus evenly-divisible
         $tData = DllStructCreate("wchar[" & $iDataSize & "]", $pMemoryBlock)
      Case Else
         ; Binary data return for all other formats
         $tData = DllStructCreate("byte[" & $iDataSize & "]", $pMemoryBlock)
   ; 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

   ; 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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...