Click here to Skip to main content
13,894,139 members
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 24 Aug 2007
Licenced CPOL

The Ultimate Toolbox Static Hyperlink

, 25 Aug 2007
Rate this:
Please Sign up or sign in to vote.
A subclassed CStatic control from the Ultimate Toolbox that provides hyperlink capabilities

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Source code and project files for this sample can be found in the samples\gui\StaticHyperLink directory of the sample projects download.


Screenshot - StaticHyperLink.jpg

The beautiful, tastefully worded, and exquisitely formatted StaticHyperLink sample dialog.

COXStaticHyperLink implements a static control that's a hyperlink to any file on your desktop or web. For example, you can use it in dialog boxes to create hyperlinks to web sites. When clicked, it opens the file/URL.

COXStaticHyperLink is based on the COXStatic class so you can use all its functions to define a control's appearance in a way you want. Of course, some new features were added to provide functionality that is similar to a hyper link on a web page.

Every COXStaticHyperLink has an associated COXHyperLinkAction that will be executed if the user clicks the mouse left button when it's over the control's window. By default, the COXHyperLinkAction operation is set to "open".

The COXStaticHyperLink can be in two states: unvisited and visited (like the common hyperlink). The control's state changes as a result of user action (left button click) but you can change it programmatically too.

To differentiate the COXStaticHyperLink from other CStatic controls, a special cursor is used. By default, the "hand cursor" that can be found in the "OXBitmapButton.rc" file (supplied with the Ultimate Toolbox) is used. This requires including a reference to the "OXBitmapButton.rc" resource in the resource file of your application. Or, of course, you can set whatever cursor you need.

To simplify the process of using the COXStaticHyperLink object you can use the window text as COXHyperLinkAction::m_sFile.

At the moment, six types of actions have been defined:

  1. None - use this type if you need the functionality this control provides but don't want to invoke any action if the user clicks on the control.
  2. Userdefined - use this type if you want to define your own action that should be taken when a hyperlink is activated. In that case, you have to set a callback message ID and a handle to the recipient window to the corresponding COXHyperLinkAction object. In your application, you have to define a unique message ID.
  3. Open - use this type if you want to open the file specified by the COXHyperLinkAction::m_sFile parameter. The file can be an executable file, a shortcut or a document file. It can also be a folder. Use this action if you want to open the website specified by m_sFile. You can also use this action if you want to send an e-mail: you can do that by setting m_sFile to "mailto:address@you.need".
  4. Print - use this type if you want to print the file specified by the COXHyperLinkAction::m_sFile parameter. The file should be a document file.
  5. Explore - use this type if you want to explore the folder specified by the COXHyperLinkAction::m_sFile parameter.
  6. Email - use this type if you want to send a message to a recipient specified by the COXHyperLinkAction::m_sFile parameter. Defined only for convenience purposes, it eventually calls the Open action.

The samples\gui\StaticHyperLink sample derives a class CCustomizableStaticHyperLink from COXStaticHyperLink and subclasses several CStatic member variables in the CStaticHyperLinkDlg class:

#include <span class="code-string">"CustomizableStaticHyperLink.h"</span>

#include <span class="code-string">"CustomizableStatic.h"</span>

#if !defined(

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000


// CStaticHyperLinkDlg dialog

class CStaticHyperLinkDlg : public CDialog
// Construction

    CStaticHyperLinkDlg(CWnd* pParent = NULL);    // standard constructor

// Dialog Data


    CCustomizableStatic        m_ctlStaticHint;
    CCustomizableStatic        m_ctlStaticSampleCaption;
    CCustomizableStaticHyperLink    m_ctlStaticSolitaire;
    CCustomizableStaticHyperLink    m_ctlStaticWebUT;
    CCustomizableStaticHyperLink    m_ctlStaticWebDundas;
    CCustomizableStaticHyperLink    m_ctlStaticFax;
    CCustomizableStaticHyperLink    m_ctlStaticEmailSales;
    CCustomizableStaticHyperLink    m_ctlStaticEmailAndrei;
    CCustomizableStaticHyperLink    m_ctlStaticClose;
    CCustomizableStaticHyperLink    m_ctlStaticBillGates;
    CCustomizableStaticHyperLink    m_ctlStaticAbout;

Then the action properties for each of the controls is set in the OnInitDialog handler:

// set action as userdefined

// don't forget to set callback message and handle to recipient window


// open website

// open new e-mail message

// open new e-mail message

// open new e-mail message, use window text as address of mail recipient


// run sol.exe (Solitaire)


// run dialer.exe (Phone Dialer)


Complete class references for the COXStaticHyperLink and COXHyperLinkAction classes can be found in the compiled HTML help documentation.


Initial CodeProject release August 2007.


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


About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
Group type: Organisation

458 members

You may also be interested in...

Comments and Discussions

Questionwasting my time! Pin
Member 84316779-Aug-13 2:11
memberMember 84316779-Aug-13 2:11 

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
Web02 | 2.8.190306.1 | Last Updated 25 Aug 2007
Article Copyright 2007 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid