Discussion:
Rich Edit problems.
(too old to reply)
Olav
2010-08-31 12:20:59 UTC
Permalink
Raw Message
Anyone here who is experienced with Rich Edit Controls?

I'm having problems with the %EM_FINDTEXTEX message. The problem is that it
reports not found no matter how I try to do it.

Anyone any clue/tips to share?

LOCAL ft AS FINDTEXTEX
LOCAL FoundAt as long
'local szFind as asciiz * 1024

'szFind = varptr(SearchTerms(1)) ' SearchTerms(1) is a dynamic string
value
ft.lpstrText = STRPTR(SearchTerms(1)) 'szFind
ft.chrg.cpMin = 0 ' search from start
ft.chrg.cpMax = -1 ' to the end of the document.. I believe
FoundAt = Sendmessage(hEdit,%EM_FINDTEXTEX,%FR_DOWN,VARPTR(ft))
IF ft.chrgText.cpMin = -1 AND ft.chrgText.cpMax = -1 THEN
? "NOT FOUND"
END IF
IF FoundAt <> -1 THEN
' if the search operation finds a match, the chrgText member of the
FINDTEXTEX structure returns the range of
' character positions that contains the matching text.
? "FOUND"
END IF
$DEBUG PRINT "FoundAt:" + STR$(FoundAt)
--
Olav
g***@yahoo.com
2010-09-06 17:59:26 UTC
Permalink
Raw Message
Post by Olav
Anyone here who is experienced with Rich Edit Controls?
I'm having problems with the %EM_FINDTEXTEX message. The problem is that it
reports not found no matter how I  try to do it.
Anyone any clue/tips to share?
   LOCAL ft AS FINDTEXTEX
   LOCAL FoundAt as long
   'local szFind as asciiz * 1024
   'szFind = varptr(SearchTerms(1))  ' SearchTerms(1) is a dynamic string
value
   ft.lpstrText = STRPTR(SearchTerms(1)) 'szFind
   ft.chrg.cpMin = 0    ' search from start
   ft.chrg.cpMax = -1  ' to the end of the document.. I believe
   FoundAt = Sendmessage(hEdit,%EM_FINDTEXTEX,%FR_DOWN,VARPTR(ft))
   IF ft.chrgText.cpMin = -1 AND ft.chrgText.cpMax = -1 THEN
     ? "NOT FOUND"
   END IF
   IF FoundAt <> -1 THEN
     ' if the search operation finds a match, the chrgText member of the
FINDTEXTEX structure returns the range of
     ' character positions that contains the matching text.
     ? "FOUND"
   END IF
   $DEBUG PRINT "FoundAt:" + STR$(FoundAt)
--
Olav
From Powerbasic forum, hope this helps.

'Borje Hagsten, Member
'posted April 12, 2005 12:44 PM

First of all - use %EM_FINDTEXTEX and the FINDTEXTEX structure
instead.
Always best to use the ..EX.. calls and structures with later
versions.

Now, what MS speaks quiet about is that the start parameter must be
like
current caret position or length of document instead of zero when
searching
upwards. DDT example, extracted from a larger code:


LOCAL lRes AS LONG, ft AS FINDTEXTEX

CONTROL SEND CBHNDL, %IDC_RICHEDIT, %EM_EXGETSEL, 0,
VARPTR(ft.chrg)
ft.chrg.cpmax = -1
ft.lpstrText = STRPTR(SearchString)

' CBWPARAM = 0, search upwards. CBWPARAM = 1, search downwards
(%FR_DOWN).
' CBWPARAM can also be combined with %FR_WHOLEWORD and
%FR_MATCHCASE, etc.
CONTROL SEND CBHNDL, %IDC_RICHEDIT, %EM_FINDTEXTEX, 0,
VARPTR(ft) TO lRes

IF result > -1 THEN
CONTROL SEND CBHNDL, %IDC_RICHEDIT, %EM_EXSETSEL, 0,
VARPTR(ft.chrgText)
CONTROL SET FOCUS CBHNDL, %IDC_RICHEDIT
ELSE
MSGBOX "Not found"
END IF
Olav
2010-09-17 15:30:36 UTC
Permalink
Raw Message
Post by Olav
Anyone here who is experienced with Rich Edit Controls?
I'm having problems with the %EM_FINDTEXTEX message. The problem is that it
reports not found no matter how I try to do it.
Anyone any clue/tips to share?
LOCAL ft AS FINDTEXTEX
LOCAL FoundAt as long
'local szFind as asciiz * 1024
'szFind = varptr(SearchTerms(1)) ' SearchTerms(1) is a dynamic string
value
ft.lpstrText = STRPTR(SearchTerms(1)) 'szFind
ft.chrg.cpMin = 0 ' search from start
ft.chrg.cpMax = -1 ' to the end of the document.. I believe
FoundAt = Sendmessage(hEdit,%EM_FINDTEXTEX,%FR_DOWN,VARPTR(ft))
IF ft.chrgText.cpMin = -1 AND ft.chrgText.cpMax = -1 THEN
? "NOT FOUND"
END IF
IF FoundAt <> -1 THEN
' if the search operation finds a match, the chrgText member of the
FINDTEXTEX structure returns the range of
' character positions that contains the matching text.
? "FOUND"
END IF
$DEBUG PRINT "FoundAt:" + STR$(FoundAt)
--
Olav
From Powerbasic forum, hope this helps.

'Borje Hagsten, Member
'posted April 12, 2005 12:44 PM

First of all - use %EM_FINDTEXTEX and the FINDTEXTEX structure
instead.
Always best to use the ..EX.. calls and structures with later
versions.

Now, what MS speaks quiet about is that the start parameter must be
like
current caret position or length of document instead of zero when
searching
upwards. DDT example, extracted from a larger code:


LOCAL lRes AS LONG, ft AS FINDTEXTEX

CONTROL SEND CBHNDL, %IDC_RICHEDIT, %EM_EXGETSEL, 0,
VARPTR(ft.chrg)
ft.chrg.cpmax = -1
ft.lpstrText = STRPTR(SearchString)

' CBWPARAM = 0, search upwards. CBWPARAM = 1, search downwards
(%FR_DOWN).
' CBWPARAM can also be combined with %FR_WHOLEWORD and
%FR_MATCHCASE, etc.
CONTROL SEND CBHNDL, %IDC_RICHEDIT, %EM_FINDTEXTEX, 0,
VARPTR(ft) TO lRes

IF result > -1 THEN
CONTROL SEND CBHNDL, %IDC_RICHEDIT, %EM_EXSETSEL, 0,
VARPTR(ft.chrgText)
CONTROL SET FOCUS CBHNDL, %IDC_RICHEDIT
ELSE
MSGBOX "Not found"
END IF



Sorry, but that didn't help. The clue was found to be Unicode or not
Unicode.
The code below - based on a Borje Hagsten routine, I think - accomplished
what I was looking for

DO
INCR idx
s = UCODE$(SearchTerms(idx))
ft.lpstrText = STRPTR(s)
ft.chrg.cpMin = 0 ' from the beginning of the document - I believe
ft.chrg.cpMax = -1 ' to the end of the document - I believe
FoundAt = Sendmessage(hRichEdit,%EM_FINDTEXTEXW,%FR_DOWN,VARPTR(ft))
$DEBUG PRINT "FoundAt:" + STR$(FoundAt) + " " +
STR$(ft.chrgText.cpMin) + " " + STR$(ft.chrgText.cpMax)
WHILE FoundAt <> -1
'INCR cnt
' if the search operation finds a match, the chrgText member of the
FINDTEXTEX structure returns the range of
' character positions that contains the matching text.
SendMessage hRichEdit, %EM_EXSETSEL, 0,VARPTR(ft.chrgText)
' wParam ad. %EM_HIDESELECTION -> Value specifying whether to hide
or show the selection. If this parameter is zero,
' the selection is shown. Otherwise, the selection is hidden.
Sendmessage hRichEdit, %EM_HIDESELECTION, 1, 0
CALL SetRichTextColor(hRichEdit,&HFF) ' a Borje Hagsten
routine
ft.chrg.cpMin = FoundAt + LEN(s)
FoundAt = Sendmessage(hRichEdit,%EM_FINDTEXTEXW,%FR_DOWN,VARPTR(ft))
'$DEBUG PRINT "FoundAt:" + STR$(FoundAt) + " " +
STR$(ft.chrgText.cpMin) + " " + STR$(ft.chrgText.cpMax)
WEND
'$DEBUG PRINT STR$(cnt)
LOOP WHILE idx < UBOUND(SearchTerms())

Loading...