Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

The Ultimate Toolbox Static Hyperlink

0.00/5 (No votes)
25 Aug 2007 1  
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 "CustomizableStaticHyperLink.h"


#include "CustomizableStatic.h"



#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 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