Click here to Skip to main content
13,802,255 members
Click here to Skip to main content
Add your own
alternative version


42 bookmarked
Posted 16 Oct 2003
Licenced CPOL

XHyperLink - yet another hyperlink control

, 16 Oct 2003
Rate this:
Please Sign up or sign in to vote.
XHyperLink is a simple drop-in hyperlink control with optional parent notification.


For many years I have used Chris Maunder's excellent Hyperlink control. Recently I needed a hyperlink that would send a notification to the parent dialog. So I started by adding this feature, and then I found that I had added other features too. Here is a list of the new features:

  • Parent notification - the parent window is optionally sent a notification message.
  • New browser window - you can optionally tell the browser to open a new window (same as if you had held down SHIFT key).
  • Background color - you can override default background color and set your own.
  • Disable tooltip - you can optionally disable tooltips for the hyperlink. This makes sense where the hyperlink only sends a notification to the parent window, but does not navigate.
  • Disable URL - optionally disable the URL. Again, this makes sense where the hyperlink only sends a notification to the parent window.
  • Dynamic resizing - you can set new window text at any time and now the control will be resized.
  • Use of IDC_HAND - the MFC hand cursor is used when it is available, before defaulting to the cursor from Winhelp.
  • GoToURL() is now static - now you can say CXHyperLink::GoToURL("").
  • XHYPERLINK_REPORT_ERROR define - by default this symbol is not defined, which will remove all the strings and message box from ReportError().
  • Resource leak fixed - added DestroyCursor(m_hLinkCursor) that was suggested by Geert Delmeiren.

How to use

To integrate XHyperLink() into your app, you first need to add following files to your project:

  • XHyperLink.cpp
  • XHyperLink.h

Then use the resource editor to add a static control to your dialog, and use Class Wizard to attach a member variable to that control. Note that when adding the static control, you must name it something other than IDC_STATIC.

Next, include the header file XHyperLink.h in the dialog's header file. Then replace the CStatic definition with CXHyperLink. Now you are ready to start using XHyperLink.

Demo app

The XHyperLinkTest.exe demo shows how to use CXHyperLink. The first hyperlink sends an email:


The next hyperlink sends a notification to the parent dialog:


and the dialog displays a message box:


The last hyperlink shows how the text and URL may be dynamically changed:



Revision history

  • Version 1.0 - 2003 October 17
    • Initial public release.


This software is released into the public domain. You are free to use it in any way you like. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.


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


About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see

You may also be interested in...

Comments and Discussions

GeneralModification: Customized Tooltips Pin
Douglas R. Keesler12-Dec-04 8:29
memberDouglas R. Keesler12-Dec-04 8:29 
This is a fabulous class. I would only like to suggest one improvement.

There may be times where you want to show a tooltip, but hide the URL -- for
example the URL is very long.

I modified this class to enable customized tooltips. I simply modified the
class declaration for the SetURL function in the XHyperLink.h file as follows:

void SetURL(CString strURL, CString strTip);

Then in the "Protected Attributes" section I added a new member variable:

CString  m_strTip;  // ToolTip text

Then in the XHyperLink.cpp file I made two modifications. First in the
PreSubclassWindow() function, at the end of the function I modified the
following statement:

// Create the tooltip
if (m_bToolTip)
    CRect rect;
    m_ToolTip.AddTool(this, m_strTip, rect, TOOLTIP_ID);

and finally, I modified the SetURL() function as follows:

 void CXHyperLink::SetURL(CString strURL, CString strTip)
m_strURL = strURL;
m_strTip = strTip;

if (::IsWindow(GetSafeHwnd()))
    m_ToolTip.UpdateTipText(strTip, this, TOOLTIP_ID);

Now from the OnInitDialog() function of your dialog class you simply call
SetURL passing two variables, the first is the actual URL and the second your
customized Tooltip string -- for example:

CString szURL = "

CString szTip = "Get MMJB Skins Here";

m_Download.SetURL(szURL, szTip);


That's All Folks!!
GeneralRe: Modification: Customized Tooltips Pin
Jaime Olivares15-May-05 6:14
memberJaime Olivares15-May-05 6:14 

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
Web03 | 2.8.181215.1 | Last Updated 17 Oct 2003
Article Copyright 2003 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid