Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using SendMessage to Find Text in a nonowned RichText ctrl
#1
I need to be able to find text in the rich edit control of another application.
Unfortunately, ctrl-F is being eaten by the application.
I thought I'd send a EM_FINDTEXT to the ctrl.
I'm not succeeding.
Anyone have a clue what I'm doing wrong?

Code:
Copy      Help
;/Insert Rich Text
function# hwndctrl str'texttofind

TEXTRANGE* tr=share
TEXTRANGE* tr2=share(hwndctrl)
memset(tr 0 sizeof(TEXTRANGE))
int stringoffset=sizeof(TEXTRANGE)+20
lpstr txt = tr+stringoffset
lpstr txt2 = tr2+stringoffset

tr.chrg.cpMin = 0
tr.chrg.cpMax = -1
strcpy(txt texttofind);; copy the string into shared space
out tr.chrg.cpMin
out tr.chrg.cpMax
out txt

tr.lpstrText = txt2;; address needs to be in nonowned control's space
int result=SendMessage(hwndctrl EM_FINDTEXT 0 tr2)
out result
ret result
#2
I tested with wordpad. First, it is unicode window. Use EM_FINDTEXTW and unicode string. Second, it does not find if FR_DOWN is not used in wParam. If used, finds text even if the caret is at the end.

Code:
Copy      Help
;/Insert Rich Text
function# hwndctrl str'texttofind


def EM_FINDTEXTW (WM_USER + 123)
def FR_DOWN          0x1

TEXTRANGE* tr=share
TEXTRANGE* tr2=share(hwndctrl)
memset(tr 0 sizeof(TEXTRANGE))
int stringoffset=sizeof(TEXTRANGE)+20
lpstr txt = tr+stringoffset
lpstr txt2 = tr2+stringoffset

tr.chrg.cpMin = 0
tr.chrg.cpMax = -1
texttofind.unicode
memcpy(txt texttofind texttofind.len+2);; copy the string into shared space

tr.lpstrText = txt2;; address needs to be in nonowned control's space
int result=SendMessage(hwndctrl EM_FINDTEXTW FR_DOWN tr2)
out result
ret result


With non unicode window it would be (not tested):
Code:
Copy      Help
;/Insert Rich Text
function# hwndctrl str'texttofind


def FR_DOWN          0x1

TEXTRANGE* tr=share
TEXTRANGE* tr2=share(hwndctrl)
memset(tr 0 sizeof(TEXTRANGE))
int stringoffset=sizeof(TEXTRANGE)+20
lpstr txt = tr+stringoffset
lpstr txt2 = tr2+stringoffset

tr.chrg.cpMin = 0
tr.chrg.cpMax = -1
strcpy(txt texttofind);; copy the string into shared space

tr.lpstrText = txt2;; address needs to be in nonowned control's space
int result=SendMessage(hwndctrl EM_FINDTEXT FR_DOWN tr2)
out result
ret result
#3
Many thanks.
This worked perfectly and helped me solidify my understanding of the situation.
Congratulations on a fantastic program.


Forum Jump:


Users browsing this thread: 1 Guest(s)