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

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:
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.
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.
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".
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.
Explore - use this type if you want to explore the folder specified by the COXHyperLinkAction::m_sFile parameter.
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
class CStaticHyperLinkDlg : public CDialog
{
public:
CStaticHyperLinkDlg(CWnd* pParent = NULL);
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;
Then the action properties for each of the controls is set in the OnInitDialog handler:
m_ctlStaticAbout.SetAction(ID_HLACTION_USERDEFINED,NULL,NULL,NULL,
SW_SHOWNORMAL,g_nAboutMsgID,GetSafeHwnd());
m_ctlStaticWebUT.SetAction(ID_HLACTION_OPEN,
_T("www.codeproject.com"));
m_ctlStaticBillGates.SetAction(ID_HLACTION_OPEN,
_T("mailto:billg@microsoft.com"));
m_ctlStaticEmailAndrei.SetAction(ID_HLACTION_OPEN,
_T("mailto:info@theUltimateToolbox.com"));
m_ctlStaticEmailSales.SetAction(ID_HLACTION_EMAIL);
m_ctlStaticSolitaire.SetAction(ID_HLACTION_OPEN,_T("sol.exe"));
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.
Initial CodeProject release August 2007.