Click here to Skip to main content
13,899,227 members
Click here to Skip to main content
Add your own
alternative version


54 bookmarked
Posted 31 Aug 2004
Licenced CPOL

Multiline Hyper Edit Control

, 31 Aug 2004
Rate this:
Please Sign up or sign in to vote.
A multiline hyper edit control derived from CEdit.

Sample Image - hyperedit.png


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.


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



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


  • virtual BOOL IsWordHyper(const CString& csToken)


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

         // 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.


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


About the Author

Web Developer
Canada Canada
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralPosFromChar() doesn't work in xp(or win2000) Pin
kingoHu3-Jan-11 16:09
memberkingoHu3-Jan-11 16:09 
GeneralFont fix for Vista Pin
Guido Sievers18-Aug-09 22:55
memberGuido Sievers18-Aug-09 22:55 
GeneralProblem with chinese characters Pin
javan24-May-09 2:53
memberjavan24-May-09 2:53 
GeneralRe: Problem with chinese characters Pin
alex.barylski25-May-09 7:11
memberalex.barylski25-May-09 7:11 
GeneralRe: Problem with chinese characters Pin
kingoHu3-Jan-11 15:51
memberkingoHu3-Jan-11 15:51 
GeneralVery Nice indeed Pin
jmeaux25-Dec-07 10:14
memberjmeaux25-Dec-07 10:14 
QuestionOCX version Pin
Kamil Maly4-Jul-07 5:11
memberKamil Maly4-Jul-07 5:11 
AnswerRe: OCX version Pin
alex.barylski4-Jul-07 8:06
memberalex.barylski4-Jul-07 8:06 
Questionoutputing multple lines in edit bow Pin
jamesx7730-Jun-07 1:00
memberjamesx7730-Jun-07 1:00 
AnswerRe: outputing multple lines in edit bow Pin
alex.barylski1-Jul-07 20:11
memberalex.barylski1-Jul-07 20:11 
GeneralBe fair to good old GDI... Pin
mykel8-Mar-07 9:39
membermykel8-Mar-07 9:39 
GeneralOptimization Pin
Rewbs8-Jul-05 17:28
memberRewbs8-Jul-05 17:28 
GeneralRe: Optimization Pin
alex.barylski11-Jul-05 7:10
memberalex.barylski11-Jul-05 7:10 
GeneralRe: Optimization Pin
conio1-Sep-05 5:04
memberconio1-Sep-05 5:04 
GeneralRe: Optimization Pin
ywimmer19-Oct-09 19:11
memberywimmer19-Oct-09 19:11 
GeneralProblems Pin
Nguyen Van Binh3-Nov-04 18:11
memberNguyen Van Binh3-Nov-04 18:11 
GeneralRe: Problems Pin
alex.barylski4-Nov-04 10:54
memberalex.barylski4-Nov-04 10:54 
GeneralRe: Problems Pin
Van Binh4-Nov-04 20:28
memberVan Binh4-Nov-04 20:28 
GeneralRe: Problems Pin
alex.barylski17-Nov-04 12:21
memberalex.barylski17-Nov-04 12:21 
GeneralRe: Problems Pin
Van Binh17-Nov-04 19:37
memberVan Binh17-Nov-04 19:37 
GeneralRe: Problems Pin
Lee Cremeans18-Aug-06 16:14
memberLee Cremeans18-Aug-06 16:14 
Generalnifty... Pin
alex.barylski3-Sep-04 16:53
memberalex.barylski3-Sep-04 16:53 
GeneralVery nice, dropped right in Pin
gwayland2-Sep-04 8:41
membergwayland2-Sep-04 8:41 
GeneralRe: Very nice, dropped right in Pin
alex.barylski2-Sep-04 10:46
memberalex.barylski2-Sep-04 10:46 
GeneralPerfect timing! Pin
Ravi Bhavnani1-Sep-04 5:04
professionalRavi Bhavnani1-Sep-04 5:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Cookies | Terms of Use | Mobile
Web04 | 2.8.190306.1 | Last Updated 1 Sep 2004
Article Copyright 2004 by alex.barylski
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid