No announcement yet.

Rich Edit Question

  • Filter
  • Time
  • Show
Clear All
new posts

  • Rich Edit Question

    I'm using a richedit control for user input. When the user copies text from a web page, I need to discard all font/ colour formatting. Can this be done?

  • #2
    Paste In Another Format

    Assuming you mean cutting from web page and pasting into an MS richedit control:
    1. Subclass the richedit control.
    2. Monitor for the Ctrl+V paste command.
    3. OpenClipboard.
    4. Browsers (at least Firefox and IE) copy multiple clipboard formats, including a standard clipboard format %CF_TEXT. (You may want to check for another which better meets your needs.) Use IsClipboardFormatAvailable to verify clipboard has data in that format.
    5. Retrieve your desired format with GetClipboardData into a memory block.
    6. Insert the memory block at the richedit control's selection.
    7. CloseClipboard, which will also free the memory block.
    Hope this helps.

    Ron Zutz


    • #3
      Ronald, sounds like a great solution but I have no idea how to do this!


      • #4
        If you mean when the user is pasting text from the clipboard, you have to subclass the RichEdit control and intercept WM_PASTE - from there you can grab the clipboard data as plain text and use EM_REPLACESEL to insert it, then exit the subclass proc without allowing the control to ever receive WM_PASTE. | Slam DBMS | PrpT Control | Other Downloads | Contact Me


        • #5
          I'll hve a dig around the forums tomorrow and see if I can find how to do this.



          • #6
            Originally posted by Steve Bouffe View Post
            I'll hve a dig around the forums tomorrow and see if I can find how to do this.

            Maybe I can save you a little time, Steve. The function "Clipboard_Get_Text" (below) will just return straight text, which you can retrieve and plug into your control. Or just use the Macro.

            '<== Start of Clipboard as an Include ==>
            'Clipboard stuff gotten from Poffs but I forget from whom
            'Note t$ must be initialized - Local t$
            Function Clipboard_Set_Text Alias "Clipboard_Set_Text" _
            (ByVal sText As String) Export As Long
            Local hData As Long, hGlob As Long
            ' ** Create a global memory object and copy the data into it
            hData = GlobalAlloc(%GMEM_MOVEABLE Or %GMEM_DDESHARE, Len(sText) + 1)
            hGlob = GlobalLock(hData)
            Poke$ hGlob, sText + Chr$(0)
            GlobalUnlock hData
            ' ** Open the clipboard
            If IsFalse(OpenClipboard(%Null)) Then
            GlobalFree hData
            Exit Function
            End If
            ' ** Paste the data into the clipboard
            EmptyClipboard 'WinAPI
            Function = SetClipboardData(%CF_TEXT, hData) 'WinAPI
            CloseClipboard 'WinAPI
            End Function
            Function Clipboard_Get_Text Alias "Clipboard_Get_Text"() Export As String
            Local zPtr As Asciiz Ptr
            OpenClipboard 0 'WinAPI
            zPtr = GetClipboardData(%CF_TEXT)
            If zPtr <> 0 Then Function = @zPtr
            CloseClipboard 'WinAPI
            End Function
            Macro Get_Clipboard = t$ = Clipboard_Get_Text 'put cb in tb at program start 
            Macro Set_Clipboard = Clipboard_Set_Text(t$)
            '<== End of Clipboard as an Include ==>
            Talk sense to a fool and he calls you foolish.
            Last edited by Gary Beene; 12 Jul 2014, 12:02 AM. Reason: Speling
            It's a pretty day. I hope you enjoy it.


            JWAM: (Quit Smoking):
            LDN - A Miracle Drug: