Click here to Skip to main content
Click here to Skip to main content

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.

Overview

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(
    AFX_STATICHYPERLINKDLG_H__ED8354A8_AC60_11D1_A3D5_0080C83F712F__INCLUDED_)
#define AFX_STATICHYPERLINKDLG_H__ED8354A8_AC60_11D1_A3D5_0080C83F712F__INCLUDED_

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

/////////////////////////////////////////////////////////////////////////////

// CStaticHyperLinkDlg dialog


class CStaticHyperLinkDlg : public CDialog
{
// Construction

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


// Dialog Data

    //{{AFX_DATA(CStaticHyperLinkDlg)

    enum { IDD = IDD_STATICHYPERLINK_DIALOG };
    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;
    //}}AFX_DATA

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

    m_ctlStaticAbout.SetAction(ID_HLACTION_USERDEFINED,NULL,NULL,NULL,
        SW_SHOWNORMAL,g_nAboutMsgID,GetSafeHwnd());

    // open website

    m_ctlStaticWebUT.SetAction(ID_HLACTION_OPEN,
        _T("www.codeproject.com"));
    // open new e-mail message

    m_ctlStaticBillGates.SetAction(ID_HLACTION_OPEN,
         _T("mailto:billg@microsoft.com"));
    // open new e-mail message

    m_ctlStaticEmailAndrei.SetAction(ID_HLACTION_OPEN,
        _T("mailto:info@theUltimateToolbox.com"));
    // open new e-mail message, use window text as address of mail recipient

    m_ctlStaticEmailSales.SetAction(ID_HLACTION_EMAIL);

    // run sol.exe (Solitaire)

    m_ctlStaticSolitaire.SetAction(ID_HLACTION_OPEN,_T("sol.exe"));

    // run dialer.exe (Phone Dialer)

    m_ctlStaticFax.SetAction(ID_HLACTION_OPEN,_T("dialer.exe"));

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

History

Initial CodeProject release August 2007.

License

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

Share

About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, 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

381 members


Comments and Discussions

 
Questionwasting my time! PinmemberMember 84316779-Aug-13 2:11 

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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 25 Aug 2007
Article Copyright 2007 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid