Click here to Skip to main content
Licence CPOL
First Posted 31 Aug 2004
Views 89,979
Bookmarked 51 times

Multiline Hyper Edit Control

By | 31 Aug 2004 | Article
A multiline hyper edit control derived from CEdit.

Sample Image - hyperedit.png

Introduction

CHyperEdit was inspired by the following message post.

CHyperEdit is a drop-in replacement for the standard MFC CEdit control, and requires no additional initialization or function calls in order to be fully functional. However, it is possible to fine tune what exactly constitutes a hyperlink-able token, and can easily be achieved in a derived CHyperEdit class by overriding the virtual function IsWordHyper; click here to view example.

Features

  • Customizable hyperlink and hover colors.
  • Multiple hyperlinks mix freely with normal text.
  • Extensible hyperlink tokenizer.

API

public

  • COLORREF GetNormalColor()
  • COLORREF GetHoverColor()
  • void SetLinkColors(COLORREF clrNormal, COLORREF clrHover)
  • CString IsHyperlink(CPoint& pt)

protected

  • virtual BOOL IsWordHyper(const CString& csToken)

Usage

Basic usage

Using CHyperEdit couldn't be easier, just add a normal EDIT control to your dialog. Right click on the EDIT control you just added and select Classwizard. Click on the Member Variables tab. Double click on the control ID of the EDIT control you just added. Enter a Member Variable name and instead of Value in the Category drop down, select Control. Under the Variable Type drop down, you should now see a CHyperEdit.

Note: You may have to delete your *.clw file and rebuild it before CHyperEdit becomes available.

If the CHyperEdit class isn't available, you can just select CEdit and replace any instance of CEdit with CHyperEdit. You may also have to manually add the required #include directives before compiling.

Advanced usage

For more control over CHyperEdit, you can choose to override the default functionality of the hyperlink tokenizer and better dictate what exactly constitutes a hyperlink-able URL. For example, the following snippet extends the default behavior by only hyperlinking tokens which include www in the domain name. This would be useful if we wished to ignore IP addresses.

// Derived class overrides this function to extend hyperlinking
BOOL CMyHyperEdit::IsWordHyper(const CString& csToken) const
{
    if(IsWhiteSpace(csToken, 0)) return FALSE;
    CString csTemp(csToken); // Make a temp copy so we can convert it's case
    csTemp.MakeLower();

         // Ignore IP addresses
    if(csTemp.Left(7) == "http://www") return TRUE;

    return FALSE; // Not a valid token by default
}

Note: You could also use a readily available regex library like regex++ for much more complex syntax checking of URLs or email addresses.

IsHyperlink is a publicly available function whose purpose may not be immediately apparent; truth be told, I only now realized that it may be useful. :)

This function returns the entire hyperlink token (if any) that the mouse is currently over. If the mouse is not over any hyperlink token when this function is called, it returns the results of a CString::Empty().

With a little imagination, some interesting possibilities arise. You could, for example, use a WM_TIMER in your application and check the return value of IsHyperlink; if it returns a valid URL for a web site, you could download the HTML page and extract the TITLE and display it in a tool tip.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

alex.barylski

Web Developer

Canada Canada

Member

I am currently seeking part time contract/freelance opportunities with any design agency or someone seeking the assistance of a professional PHP developer.
 
Capabilities/Experience:
 
  • PHP/JavaScript/MySQL
  • jQuery/DHTML
  • 100% W3C validated XHTML/CSS (table-less design/layout)
  • Expert in object oriented techniques, practices and principles
  • Familiar with most common design patterns and security exploits
 
I strive for simplicity and following KISS keeps code fast, efficient and secure.
 
I am looking to develop small/medium applications (a few months at most). Please note, If you require me to change an existing system, leeway is needed to learn the code base first. How long this takes will vary based on code complexity, documentation, etc.
 
I am located in Central Canada and should be readily available during regular business hours (8a-6p). If you wish to speak to me on the phone (outside of a sales call or initial consultation) you will be billed an additional fee for phone communication. MSN or Email is the prefered line of communication for support requests, feature suggestions, etc.
 

Cheers,
Alex

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralPosFromChar() doesn't work in xp(or win2000) Pinmemberkingwho16:09 3 Jan '11  
GeneralFont fix for Vista PinmemberGuido Sievers22:55 18 Aug '09  
GeneralProblem with chinese characters Pinmemberjavan2:53 24 May '09  
GeneralRe: Problem with chinese characters PinmemberXanderXP7:11 25 May '09  
GeneralRe: Problem with chinese characters Pinmemberkingwho15:51 3 Jan '11  
GeneralVery Nice indeed Pinmemberjmeaux10:14 25 Dec '07  
QuestionOCX version PinmemberKamil Maly5:11 4 Jul '07  
AnswerRe: OCX version PinmemberHockey8:06 4 Jul '07  
Questionoutputing multple lines in edit bow Pinmemberjamesx771:00 30 Jun '07  
AnswerRe: outputing multple lines in edit bow PinmemberHockey20:11 1 Jul '07  
GeneralBe fair to good old GDI... Pinmembermykel9:39 8 Mar '07  
GeneralOptimization PinmemberRewbs17:28 8 Jul '05  
GeneralRe: Optimization PinmemberHockey7:10 11 Jul '05  
GeneralRe: Optimization Pinmemberconio5:04 1 Sep '05  
GeneralRe: Optimization Pinmemberyotamwimmer19:11 19 Oct '09  
GeneralProblems PinmemberNguyen Van Binh18:11 3 Nov '04  
GeneralRe: Problems PinmemberHockey10:54 4 Nov '04  
GeneralRe: Problems PinmemberVan Binh20:28 4 Nov '04  
GeneralRe: Problems PinmemberHockey12:21 17 Nov '04  
GeneralRe: Problems PinmemberVan Binh19:37 17 Nov '04  
GeneralRe: Problems PinmemberLee Cremeans16:14 18 Aug '06  
Generalnifty... PinmemberHockey16:53 3 Sep '04  
GeneralVery nice, dropped right in Pinmembergwayland8:41 2 Sep '04  
GeneralRe: Very nice, dropped right in PinmemberHockey10:46 2 Sep '04  
GeneralPerfect timing! PinmemberRavi Bhavnani5:04 1 Sep '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 1 Sep 2004
Article Copyright 2004 by alex.barylski
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid