Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using SendMessage to Find Text in a nonowned RichText ctrl
#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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)