Click here to Skip to main content
13,297,048 members (54,951 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 27 Jun 2001

Hyperlink Text View Control

, 20 Jun 2002
Rate this:
Please Sign up or sign in to vote.
Control that shows text and automatically finds and highlights hyperlinks (like http://, www. etc.) so that user can click on them.
<!-- Download Links --> <!-- Article image -->

Sample Image - hv.gif

<!-- Add the rest of your HTML here -->


This control works like a static control, but have some enhancements.
The main is that it recognizes and shows hyperlinks in text.


  • Automatically recognizes hyperlinks
  • Word wrapped text view
  • Highlights hyperlink when hover
  • Auto show scrollbars
  • Manually added hyperlinks that can do some operations
  • Tool tips for hyperlinks


Next files required to be included before "HyperTextCtr.h":

Also this control uses two STL classes: std::vector and std::list

How to use it in your own applications

  1. Create WTL project and add following header files to your stdafx.h file:
    // WTL includes
    #include <span class="code-keyword"><atlstr.h></span>
    #include <span class="code-keyword"><atltypes.h></span>
    #include <span class="code-keyword"><atlctrls.h></span>
    #include <span class="code-keyword"><atlscrl.h></span>
    // Hyper Text Control
    #include <span class="code-string">"HyperTextCtrl.h"</span>
  2. To support mouse wheel define the following in stdafx.h before all includes:
    #define _WIN32_WINNT 0x0400
  3. Add HyperTextControl.h to solution

  4. Add variable declaration inside view class:
    CHyperTextCtrl m_hc;
  5. Create control and set control's properties in WM_CREATE message handler:
    m_hc.Create(m_hWnd, rcDefault, NULL, 
    CFont fnt;
    fnt.CreatePointFont(90, "Tahoma");
    m_hc.SetFont(fnt.Detach()); // default font is Times New Roman
    m_hc.SetLinkColor(RGB(0,130,0)); // default is blue
    m_hc.SetHoverColor(RGB(0,30,0)); // default is red
    Supported additional control styles:
    • HTC_WORDWRAP Word wrap text
    • HTC_AUTO_SCROLL_BARS Auto show/hide scroll bars
    • HTC_UNDERLINE_LINKS Underline links
    • HTC_UNDERLINE_HOVER Underline hover links
    • HTC_ENABLE_TOOLTIPS Enable hyperlink tool tips

  6. Add text and/or manually add hyperlinks:
    m_hc.SetWindowText("The is a very nice place for the sources.");
    m_hc.AppendHyperLink("Launch notepad\n", "Click here to open notepad", "notepad.exe", "");
    m_hc.AppendText("Send mail to ");
    m_hc.AppendHyperLink("author\n\n", "Click here to send e-mail", "mailto:maq@...","");
    m_hc.AppendHyperLink("Close this window\n", "Click here to close window", 
                         m_hWnd, WM_CLOSE, 0, 0);
  7. Add the following code to WM_SIZE message handler of view to fit control into
    the view when resizing:
    CRect rc;


This control was created with VC7, WTL7.
It has been tested on Windows XP Pro English.


+ CHyperTextCtrlFSB - uses flat scroll bars
+ SetTextColor, SetBkColor
- bugs fixed

+ Now CHyperTextCtrl inherits from CHyperTextCtrlT<>

+ .cpp file removed. Now all code is in HyperTextCtrl.h
- bugs fixed
* Tested on WinXP, VC++7, WTL7

+ Control was created.
* Tested on Win2K, VC++6 SP3, WTL3.1


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Magomed Abdurakhmanov
Web Developer
Russian Federation Russian Federation
No Biography provided

You may also be interested in...


Comments and Discussions

Generalerror with vs2005 wtl8 Pin
gaoyh23-Sep-08 23:48
membergaoyh23-Sep-08 23:48 
GeneralHelp with headers Pin
xrigau15-Sep-03 21:21
memberxrigau15-Sep-03 21:21 
GeneralI added HTC_CENTER Pin
Phlip30-Jan-03 11:46
memberPhlip30-Jan-03 11:46 
Here's the bio-patch for anyone curious:

#define HTC_ENABLE_TOOLTIPS 16 // enable hyperlink tool tips
#define HTC_CENTER (1 << 5) // like HTML <center>


::GetTextExtentExPoint(dc, s + Offset, Len, 0, NULL, NULL, &sz);

int exx (0);

if (check_bits(dwStyle, HTC_CENTER))
RECT rect;
int width = rect.right - rect.left;
exx = (width - / 2;

rcBounds.left = XPos + exx;;
rcBounds.right = XPos + exx; = ypos;

Just search for the first line of each of those blocks, then apply the edits.

Have a good one!

-- Now collecting votes for a new group:
news:alt.flame.moderated --

GeneralGreat control! But, at the risk of pedantry... Pin
Phlip20-Nov-02 21:00
memberPhlip20-Nov-02 21:00 
GeneralRe: Great control! But, at the risk of pedantry... Pin
Magomed G. Abdurakhmanov20-Nov-02 22:22
memberMagomed G. Abdurakhmanov20-Nov-02 22:22 
GeneralRe: Great control! But, at the risk of pedantry... Pin
Magomed G. Abdurakhmanov20-Nov-02 22:24
memberMagomed G. Abdurakhmanov20-Nov-02 22:24 
GeneralRe: Great control! But, at the risk of pedantry... Pin
Magomed G. Abdurakhmanov20-Nov-02 22:24
memberMagomed G. Abdurakhmanov20-Nov-02 22:24 
GeneralRe: Great control! But, at the risk of pedantry... Pin
Phlip21-Nov-02 9:14
memberPhlip21-Nov-02 9:14 
GeneralGreat control!! Pin
Kronuz18-Oct-02 8:47
sussKronuz18-Oct-02 8:47 
GeneralRe: Great control!! Pin
Magomed G. Abdurakhmanov20-Oct-02 0:31
memberMagomed G. Abdurakhmanov20-Oct-02 0:31 
GeneralNice but.... Pin
loket21-Jun-02 13:02
memberloket21-Jun-02 13:02 
GeneralRe: Nice but.... Pin
Magomed G. Abdurakhmanov22-Jun-02 8:22
memberMagomed G. Abdurakhmanov22-Jun-02 8:22 
GeneralRe: Nice but.... Pin
Magomed G. Abdurakhmanov23-Jun-02 3:05
memberMagomed G. Abdurakhmanov23-Jun-02 3:05 
GeneralRe: Nice but.... Pin
Magomed G. Abdurakhmanov23-Jun-02 5:26
memberMagomed G. Abdurakhmanov23-Jun-02 5:26 
GeneralRe: Nice but.... Pin
Anna-Jayne Metcalfe12-Jun-03 23:28
memberAnna-Jayne Metcalfe12-Jun-03 23:28 
Generalatlres.h is missing from the RES directory Pin
Marat Bedretdinov30-Jun-01 12:34
memberMarat Bedretdinov30-Jun-01 12:34 
GeneralRe: atlres.h is missing from the RES directory Pin
Magomed G. Abdurakhmanov2-Jul-01 7:52
memberMagomed G. Abdurakhmanov2-Jul-01 7:52 

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 | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 21 Jun 2002
Article Copyright 2001 by Magomed Abdurakhmanov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid