01-25-2018, 10:59 PM
Thanks Gintaras for this successful answer.
With this version of RichEditHighlight, I can almost make a continuously format-updating tool without changing the cursor position i.e. if i type the phrase "the ball is red" then as soon as findrx finds red, it will change the text to red, even as I go on to type additional text.
But the problem is that it gets glitchy because it keeps on trying to re-apply the formatting to previous instances which have already been turned red. Is it possible to determine whether some formatting, whether it be bold, underline, italicize or text/background color is already true before applying? I tried below using getsel with the CF_RTF limited to the offsets of interest. It works in theory, but it is so jumpy it makes interaction and typing practically impossible. Is there any way to make this more of a background process for the user?
I know from http://www.quickmacros.com/forum/showthr...p?tid=1406 that I could use GetRTF with SendMessage(hre EM_STREAMOUT SF_RTF &es) but the application with the RichEdit control is external so I would need to do the dll injection via hook that you described in the other thread. If there is not a way to salvage the code below, could you suggest how I could do the dll injection. The external app is 32-bit. I work with some folks who could do the C programming if I could just give them some of the details.
Any advice?
Thanks so much, S
Trigger Aj
With this version of RichEditHighlight, I can almost make a continuously format-updating tool without changing the cursor position i.e. if i type the phrase "the ball is red" then as soon as findrx finds red, it will change the text to red, even as I go on to type additional text.
But the problem is that it gets glitchy because it keeps on trying to re-apply the formatting to previous instances which have already been turned red. Is it possible to determine whether some formatting, whether it be bold, underline, italicize or text/background color is already true before applying? I tried below using getsel with the CF_RTF limited to the offsets of interest. It works in theory, but it is so jumpy it makes interaction and typing practically impossible. Is there any way to make this more of a background process for the user?
I know from http://www.quickmacros.com/forum/showthr...p?tid=1406 that I could use GetRTF with SendMessage(hre EM_STREAMOUT SF_RTF &es) but the application with the RichEdit control is external so I would need to do the dll injection via hook that you described in the other thread. If there is not a way to salvage the code below, could you suggest how I could do the dll injection. The external app is 32-bit. I work with some folks who could do the C programming if I could just give them some of the details.
Any advice?
Thanks so much, S
Trigger Aj

int w=win("Document - WordPad" "WordPadClass")
int hwndre = id(59648 w) ;;editable text 'Rich Text Window'
rep 60
,if child(mouse) != hwndre; 0.1; continue
,str ReportText.getwintext(hwndre)
,ReportText.findreplace("[]" "[10]")
,;out ReportText
,int i; ARRAY(CHARRANGE) a ;ARRAY(str) s
,findrx(ReportText "(red)|(blue)|(green)" 0 4 a)
,findrx(ReportText "(red)|(blue)|(green)" 0 4 s)
,out F"Total: {a.len}"
,if !a.len; 1;continue
,for i 0 a.len
,,out F"[]{i}: '{s[0 i]}'"
,,int offset(a[0 i].cpMin) length(a[0 i].cpMax-a[0 i].cpMin)
,,str t.get(ReportText offset length)
,,;out "offset=%i length=%i %s" offset length t
,,int selStart selEnd
,,SendMessage hwndre EM_GETSEL &selStart &selEnd
,,SendMessage hwndre EM_SETSEL a[0 i].cpMin a[0 i].cpMax
,,str ColorCaptured = s[0 i]
,,str SelRtf.getsel(0 CF_RTF hwndre)
,,out F"[9][9]{SelRtf}"
,,int r g b
,,str ColorRtf
,,sel s[0 i]
,,,case "red" ColorRtf = "\colortbl ;\red255\green0\blue0"; r = 255; g = 0; b = 0
,,,case "green" ColorRtf = "\colortbl ;\red0\green255\blue0"; r = 0; g = 255; b = 0
,,,case "blue" ColorRtf = "\colortbl ;\red0\green0\blue255"; r = 0; g = 0; b = 255
,,int textcolor = ColorFromRGB(r g b)
,,if find(SelRtf ColorRtf) > -1
,,,out F"[9]already '{ColorCaptured}'"
,,else
,,,__ProcessMemory m.Alloc(hwndre 1000)
,,,if(IsWindowUnicode(hwndre))
,,,,CHARFORMAT2W cfw.cbSize=sizeof(cfw)
,,,,if(textcolor) cfw.dwMask|CFM_COLOR; cfw.crTextColor=textcolor
,,,,m.Write(&cfw sizeof(cfw))
,,,else
,,,,CHARFORMAT2A cfa.cbSize=sizeof(cfa)
,,,,if(textcolor) cfa.dwMask|CFM_COLOR; cfa.crTextColor=textcolor
,,,,m.Write(&cfa sizeof(cfa))
,,,SendMessage hwndre EM_SETCHARFORMAT SCF_SELECTION m.address
,,,0.5
,,SendMessage hwndre EM_SETSEL &selStart &selEnd
,,0.5