Posts: 1,006
Threads: 330
Joined: Mar 2007
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
Posts: 12,097
Threads: 142
Joined: Dec 2002
Function
dialog_rich_edit_RTF_string
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)
Posts: 1,006
Threads: 330
Joined: Mar 2007
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
Posts: 12,097
Threads: 142
Joined: Dec 2002
If the control is in other process, use __ProcessMemory class.
Posts: 1,006
Threads: 330
Joined: Mar 2007
Thanks Gintaras,
I tried as below but still crashes WordPad. Any thoughts? Thanks! S
Function
RichEditRtfString
\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)
Posts: 12,097
Threads: 142
Joined: Dec 2002
Need to write string and t. And not sizeof.
Posts: 1,006
Threads: 330
Joined: Mar 2007
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
Posts: 12,097
Threads: 142
Joined: Dec 2002
Macro
Macro3028
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))
Posts: 1,006
Threads: 330
Joined: Mar 2007
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