Click here to Skip to main content
13,344,765 members (61,175 online)
Click here to Skip to main content
Add your own
alternative version


35 bookmarked
Posted 26 Dec 2002

A Static Hyperlink control

, 26 Dec 2002
Rate this:
Please Sign up or sign in to vote.
An article describing the usage of a CStatic derived Hyperlink control


This article describes a simple CStatic derived Hyperlink control, which can be used in your project to link to any URL such as your company's website or EMail. In addition to that, this control can fire an event  to the parent dialog, it can be used to popup another dialog, or whatever else you want to do.

This controls features include :-

  1. Link to the URL  and EMails ,and can be link in to another child dialog
  2. Customize the colors of link, visited and hover (if you do not specify, they use the standard style)
  3. Enable/disable the Tooltip, and customize the back-color and text-color of the tool-tip

Using the code

For using this class in your project, you have to do :-

  1. Add MyHyperlink.cpp and MyHyperlink.h to the project.
  2. Include MyHyperlink.h in the header file where the controls are defined
  3. Create (or edit) a member variable for each button you want to customize as CMyHyperlink. If the Class Wizard doesn't show the CMyHyperlink type, select CStatic and then edit the code manually.

In the demo project, m_Static1, m_Static2, m_Static3 are the CMyHyperlink controls :-

//Set the target URL 
//Enable showing the Tooltip
//Set the Tooltiptext
m_Static1.SetTootTipText("Click Here to go Codeproject");
//Set the tooltip Background Color
m_Static1.SetToolTipBgColor(RGB(0, 0, 0));
//Set the Tooltip Text Color
m_Static1.SetToolTipTextColor(RGB(0, 255, 0));

// Change the default Linktext, HoverText, Visited Colors 
// if you don't specify the colors the control will use the 

m_Static1.SetLinkColor(RGB(255, 0, 0)); 
m_Static1.SetHoverColor(RGB(0, 0, 255));
m_Static1.SetVisitedColor(RGB(0, 13, 0));

m_Static2.SetTootTipText("Click here to Email Me..");

//The SetFireChild(1) method will enable the 
//event firing to the parent dialog
m_Static3.SetTootTipText("Click Here to Fire An event to parent");

For trapping the event from the CMyHyperlink control you must trap the message in your dialog by adding the ON_MESSAGE(_HYPERLINK_EVENT,OnChildFire) in the MESSAGE MAP of the dialog, the definition of the function is like

void CControlContainerDlg::OnChildFire(WPARAM wparam, LPARAM lparam)           

The WPARAM contains the ID of the control from where the Event coming from.

Points of Interest

During the development, I faced a problem to get the standard windows  hand cursor when the mouse is over the controls. I searched for that  in various resources and at last I found that from a site, they described how to load the hand cursor resource from a file, but here I also included a resource of hand cursor with id IDC_CURSOR_HAND


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Simplicity is the ultimate sophistication. Believing in application, then the technology.

You may also be interested in...


Comments and Discussions

GeneralTo make Hand appeir Pin
tetedanus21-Feb-11 6:28
membertetedanus21-Feb-11 6:28 
Generalsmall problem Pin
wcccodeproject30-Dec-10 21:52
memberwcccodeproject30-Dec-10 21:52 
I run this program on windosw 7,the cursor is disappear when I move the it to the hyperlink,need I add a cursor resource to the project?
GeneralUnicode Pin
dima polyakov22-May-07 14:31
memberdima polyakov22-May-07 14:31 
GeneralGood class, but bad code quality Pin
math|fourier11-Oct-06 5:41
membermath|fourier11-Oct-06 5:41 
GeneralRe: Good class, but bad code quality Pin
Renjith Ramachandran23-Nov-06 19:43
memberRenjith Ramachandran23-Nov-06 19:43 
GeneralGood Control Pin
baiju.km2-Nov-05 3:38
memberbaiju.km2-Nov-05 3:38 
Generalwithout using MFC Pin
maharsoft6-Jan-04 3:17
membermaharsoft6-Jan-04 3:17 
QuestionIncorrect colors? Pin
dennisV3-Dec-03 15:03
memberdennisV3-Dec-03 15:03 
AnswerRe: Incorrect colors? Pin
foxbat3-Jan-04 3:19
memberfoxbat3-Jan-04 3:19 
GeneralHyperlink Color in Win XP Pin
SVarnavsky18-Oct-03 12:40
memberSVarnavsky18-Oct-03 12:40 
GeneralRe: Hyperlink Color in Win XP Pin
renjith_sree6-Feb-06 8:11
memberrenjith_sree6-Feb-06 8:11 
GeneralBug Pin
ironfelix2-Sep-03 21:56
memberironfelix2-Sep-03 21:56 
GeneralBackground color and transparency Pin
Appstmd18-Jul-03 1:02
memberAppstmd18-Jul-03 1:02 
Questionwhy this class can not use create? Pin
poor31-May-03 23:01
susspoor31-May-03 23:01 
AnswerRe: why this class can not use create? Pin
Renjith R31-May-03 23:35
memberRenjith R31-May-03 23:35 
GeneralRe: why this class can not use create? Pin
saptor20-Jan-05 12:17
membersaptor20-Jan-05 12:17 
GeneralRe: why this class can not use create? Pin
zwzzj16-Mar-07 21:58
memberzwzzj16-Mar-07 21:58 
GeneralBig Big Bugs!!! Pin
psusong31-May-03 18:02
memberpsusong31-May-03 18:02 
GeneralRe: Big Big Bugs!!! Pin
tijske22-Mar-06 3:22
membertijske22-Mar-06 3:22 
Generalexcellent Pin
asrx28-Jan-03 2:11
memberasrx28-Jan-03 2:11 
GeneralRe: excellent Pin
Renjith R28-Jan-03 5:06
memberRenjith R28-Jan-03 5:06 
GeneralStandard hand cursor Pin
Tak29-Dec-02 4:57
memberTak29-Dec-02 4:57 
GeneralRe: Standard hand cursor Pin
Renjith R29-Dec-02 7:30
memberRenjith R29-Dec-02 7:30 
GeneralRe: Standard hand cursor Pin
Tak29-Dec-02 7:37
memberTak29-Dec-02 7:37 
GeneralRe: Standard hand cursor Pin
Renjith R29-Dec-02 14:59
memberRenjith R29-Dec-02 14:59 

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 | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 27 Dec 2002
Article Copyright 2002 by Renjith Ramachandran
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid