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?
Announcement
Collapse
No announcement yet.
Rich Edit Question
Collapse
X
-
Paste In Another Format
Assuming you mean cutting from web page and pasting into an MS richedit control:- Subclass the richedit control.
- Monitor for the Ctrl+V paste command.
- OpenClipboard.
- 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.
- Retrieve your desired format with GetClipboardData into a memory block.
- Insert the memory block at the richedit control's selection.
- CloseClipboard, which will also free the memory block.
Ron Zutz
-
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.
Comment
-
Originally posted by Steve Bouffe View PostI'll hve a dig around the forums tomorrow and see if I can find how to do this.
Cheers!
Code:'<== 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.
Euripides
===============================================It's a pretty day. I hope you enjoy it.
Gösta
My Ego Site: http://www.SwedesDock.comPB Newby Tips: http://www.swedesdock.com/powerbasic/pb_shortcuts.htmlJWAM: (Quit Smoking): http://www.SwedesDock.com/smokingLDN - A Miracle Drug: http://www.SwedesDock.com/LDN/
Comment
Comment