Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inserting RTF code to show up as RTF formatted text in RichEdit Field
#1
Hi Gintaras,
Hope all is well. I was wondering if there was a way to insert a string of RTF code: e.g.


Quote:{\rtf1 \ansi \deff0 {\fonttbl {\f0 Monotype Corsiva;}} \qc \f0 \fs120 \i \b Hello,\line World!}



and have it appear properly formatted as RTF in RichEditField.

I saw the function RichEditLoad but this seems to only take .rtf file of text already preformatted as RTF (e.g. using RTF editor like wordpad) and then loading as RTF formatted text. If I supply actual RTF code (like above) in .txt file, it inserts directly as simple text.

I am hoping to supply something like the exact string above and replace what is in RichEditField.

Or even better, getting RTF code out of RichEdit box using getsel with CF_RTF and then editing RTF tags slightly, then re-inserting to appear as RTF-formatted text.

I know that these will have to be in same exe/qm.

I think of this as similar to changing html formatting tag and then refreshing browser or reloading html file - but I understand that Win32/Winforms etc,  is different than html!

Is this possible?

Thanks so much,
S
#2
Function dialog_rich_edit_RTF_string
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 RichEdit20A 0x54233044 0x200 8 8 208 104 ""
;4 Button 0x54032000 0x0 8 116 48 14 "Test"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "3"
str re3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 4 goto gTest
ret 1

;gTest
str rtf=
;{\rtf1 \ansi \deff0 {\fonttbl {\f0 Monotype Corsiva;}} \qc \f0 \fs120 \i \b Hello,\line World!}

SETTEXTEX t
SendMessageW(id(3 hDlg) EM_SETTEXTEX &t rtf)
#3
That's fantastic. I tried it with Wordpad and it crashed so I am assuming that this also would require DLL injection.
I think I am close on figuring that out.
Thanks again for the above example!
S
#4
If the control is in other process, use __ProcessMemory class.
#5
Thanks Gintaras,
I tried as below but still crashes WordPad. Any thoughts? Thanks! S

Function RichEditRtfString
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 RichEdit20A 0x54233044 0x200 8 8 208 104 ""
;4 Button 0x54032000 0x0 8 116 48 14 "Test"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "3"
str re3
if(!ShowDialog("RichEditRtfString" &RichEditRtfString &controls)) ret

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 4    goto gTest
ret 1

;gTest
str rtf = "{\rtf1 \ansi \deff0 {\fonttbl {\f0 Monotype Corsiva;}} \qc \f0 \fs120 \i \b Hello,\line World!}"
int w=win("Document - WordPad" "WordPadClass")
int c=  id(59648 w) ;;editable text 'Rich Text Window'

__ProcessMemory m.Alloc(c 1000)

m.WriteStr(rtf sizeof(rtf))
SETTEXTEX t
SendMessageW(c EM_SETTEXTEX &t m.address)
#6
Need to write string and t. And not sizeof.
#7
Thanks but still having trouble. I am confused by what you mean by "writing string and t". Could you possibly write a short example. Sorry for the bother.
Much appreciated!,
S
#8
Macro Macro3028
Code:
Copy      Help
str rtf = "{\rtf1 \ansi \deff0 {\fonttbl {\f0 Monotype Corsiva;}} \qc \f0 \fs120 \i \b Hello,\line World!}"
int w=win("Document - WordPad" "WordPadClass")
int c=  id(59648 w) ;;editable text 'Rich Text Window'

__ProcessMemory m.Alloc(c rtf.len+100)

SETTEXTEX t
m.Write(&t sizeof(t))
m.WriteStr(rtf sizeof(t))
byte* p=m.address
SendMessageW(c EM_SETTEXTEX p p+sizeof(t))
#9
Whoah! Works perfectly!!!
Looking at the __ProcessMemory members, I had the strong feeling I would have to get into declarations like byte* etc.
Way above my level but I will study your example as I utilize it in various situations!!!
I am in awesome gratitude as always!
S


Forum Jump:


Users browsing this thread: 1 Guest(s)