08-28-2006, 07:40 AM
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.
With non unicode window it would be (not tested):
;/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 resultWith non unicode window it would be (not tested):
;/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