News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Uncle Tom, the RichEdit control's little helper

Started by jj2007, March 03, 2023, 03:01:17 AM

Previous topic - Next topic

jj2007

Our buggy friend, the RichEdit control, has lots of more or less useful messages. And it has a second option for communicating with you: the Text Object Model alias TOM.

Now, if you think "that smells suspiciously of COM", you are absolutely right. For example, a proc that inserts a string into a given range might look like this (actually a workaround for the infamous EM_EXSETSEL bug):

_TomRepSel proc uses esi edi pChrg, _Insert$ ; ptr to CHARRANGE, string to insert
  call TomInit ; load ITextDocument interface into edi
  mov ecx, pChrg
  mov eax, [ecx.CHARRANGE.cpMax]
  push eax ; cpMax
  push eax ; cpMin=cpMax for EXSETSEL below
  CoInvoke pInterface, ITextDocument.Range, [ecx.CHARRANGE.cpMin], eax, addr ReTom.mbtRange
  lea edi, ReTom.mbtRange
  CoInvoke pInterface, ITextRange.SetFormattedText, ReTom.mbtRange ; set the range to formatted (otherwise shortcuts fail)
  CoInvoke pInterface, ITextRange.SetText, Ole$(_Insert$)
  invoke SendMessage, _hRE, EM_EXSETSEL, 0, esp ; no bug for end of selection
  pop edx
  pop ecx
  ret
_TomRepSel endp


That looks evil indeed, and it needs the latest MasmBasic version. For the time being, I have used TOM only to get and set text (see attachment), but it looks promising. There are a wealth of new functions to study (and some crispy new bugs, pardon: features).

\Masm32\MasmBasic\MasmBasic.inc has implemented the most important interfaces; look below MbTOM. I'll continue playing if I find the time, and maybe keep you posted ;-)