Richedit 2.0 and CFM_LINK

I have a function AddText that adds text to a rich edit control . The function is supposed to catch messages starting with http:// or ftp:// or any other internet prefix , and apply the CFM_LINK to the string until a space is found . This is part of it : ( ttt contains the string to add  , and w[k]->p->rEdit and ccw[k]->p->rEdit are TRichEdit objects  )

for( unsigned int p = 0 ; p < strlen(ttt) ; )
      /* FIRST of ALL : Test for EM_LINK */
      if (REC_LINKS)
            if (!IsLinkingActive)
                  // Enable if next is a link string
                  if (strlen(ttt + p) < 10)
                        goto AfterLinking;
                        if (
                        (strncmpi(ttt + p,"http://",7) == 0) ||
                        (strncmpi(ttt + p,"www.",4) == 0) ||
                        (strncmpi(ttt + p,"telnet://",9) == 0) ||
                        (strncmpi(ttt + p,"ftp://",6) == 0) ||
                        (strncmpi(ttt + p,"mailto:",7) == 0))
                        w[k]->p->rEdit->ToggleCharAttribute(CFM_LINK, CFE_LINK);
                  IsLinkingActive = true;
            else // active linking
                  if ((unsigned char)ttt[p] == 0x20 )
                        w[k]->p->rEdit->ToggleCharAttribute(CFM_LINK, CFE_LINK);
                        IsLinkingActive = false;


The problem is that the CFE_LINK is applied to the WHOLE line ! . That means,  if I have a line
" please go to" , the CFM_LINK is applied to the whole string .
Please help
Who is Participating?
duneramConnect With a Mentor Commented:
first look:  It appears as though you are not specifying an ending position for the end of the link.

You probably need to add logic to turn off the toggle in the 'after linking section' to get it to terminate correctly.

In the stuff before the http:// key you need to make sure you don't start the 'link until you are supposed to:

Instead of 'p'  use

w[k]->p->rEdit->ToggleCharAttribute(CFM_LINK, CFE_LINK);

w[k]->(ttt+p)->rEdit->ToggleCharAttribute(CFM_LINK, CFE_LINK);

Use the same when turning it off.

You should also increase the points here... but this should work a bit better

WxWAuthor Commented:
Nope . Tje w[k]->p is NOT the same as the ttt[p] . ttt[p] is an index to the string ttt , and w[k]->p is a TWindow . AND , I check for a space character after a string to terminate the link  as you saw in
if ((unsigned char)ttt[p] == 0x20 )

I was refering to how you do your strncmps...

"strncmpi(ttt + p,"mailto:",7) == 0)) "

You are taking the base ttt and adding the offset p

When you do that and eventially find a keyword, like 'ttt+p' --> "m" in "mailto:"

then you will want to start the link process at ttt+p, not 'p'  .

if your index 'p' is different from the 'p' in the pointer string, you should consider changing the names of one of them to avoid the confusion.  I assumed (since I didn't have the definition of p to be the same index you were using as the index of the loop.
All Courses

From novice to tech pro — start learning today.