Solved

Richedit 2.0 and CFM_LINK

Posted on 1998-09-12
3
1,269 Views
Last Modified: 2013-12-26
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;
                        }
                  }

            AfterLinking:


The problem is that the CFE_LINK is applied to the WHOLE line ! . That means,  if I have a line
" please go to http://www.com" , the CFM_LINK is applied to the whole string .
Please help
0
Comment
Question by:WxW
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
duneram earned 20 total points
ID: 1299785
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

0
 
LVL 6

Author Comment

by:WxW
ID: 1299786
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 )

0
 
LVL 2

Expert Comment

by:duneram
ID: 1299787
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.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now