Inserting RTF code to show up as RTF formatted text in RichEdit Field stupomer Posting Freak Posts: 950 Threads: 318 Joined: Mar 2007 03-21-2018, 12:05 AM 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 Gintaras Administrator Posts: 10,659 Threads: 123 Joined: Dec 2002 03-23-2018, 05:41 AM Function dialog_rich_edit_RTF_string Code: ```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)``` stupomer Posting Freak Posts: 950 Threads: 318 Joined: Mar 2007 03-23-2018, 10:30 PM 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 Gintaras Administrator Posts: 10,659 Threads: 123 Joined: Dec 2002 03-24-2018, 05:03 AM If the control is in other process, use __ProcessMemory class. stupomer Posting Freak Posts: 950 Threads: 318 Joined: Mar 2007 03-30-2018, 02:23 AM Thanks Gintaras, I tried as below but still crashes WordPad. Any thoughts? Thanks! S Function RichEditRtfString Code: ```\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)``` Gintaras Administrator Posts: 10,659 Threads: 123 Joined: Dec 2002 03-30-2018, 05:35 AM Need to write string and t. And not sizeof. stupomer Posting Freak Posts: 950 Threads: 318 Joined: Mar 2007 04-03-2018, 02:36 PM 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 Gintaras Administrator Posts: 10,659 Threads: 123 Joined: Dec 2002 04-03-2018, 03:04 PM Macro Macro3028 Code: ```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))``` stupomer Posting Freak Posts: 950 Threads: 318 Joined: Mar 2007 04-03-2018, 09:05 PM 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 « Next Oldest | Next Newest »