Click here to Skip to main content
Licence Ms-PL
First Posted 26 Dec 2002
Views 121,599
Downloads 2,845
Bookmarked 32 times

A Static Hyperlink control

By | 26 Dec 2002 | Article
An article describing the usage of a CStatic derived Hyperlink control

Introduction

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 
m_Static1.SetLinkUrl("www.codeproject.com");
//Enable showing the Tooltip
m_Static1.ActiveToolTip(1);
//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 
//defaults..

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

m_Static2.SetLinkUrl("mailto:renjith_sree@hotmail.com");
m_Static2.ActiveToolTip(1);
m_Static2.SetTootTipText("Click here to Email Me..");

//The SetFireChild(1) method will enable the 
//event firing to the parent dialog
m_Static3.SetFireChild(1);
m_Static3.ActiveToolTip(1);
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

License

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

About the Author

Renjith Ramachandran

Architect

India India

Member

Renjith is a simple & cool guy from kerala, A hardcore designer, programmer and a budding analyst.
 
He is an open source freak, among them he enjoyed some work with the mozilla firefox.
 
He loves to listen to music,he loves to play and watch football and long drives while playing the music.
 
He is the founder of INDIAN IT FORUM - www.indianITforum.com - the largest forum for indian IT professionals.
 
Now a days he is exploring the good old unix stuffs, because his clients needs to do some more things in to it.
 



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralTo make Hand appeir Pinmembertetedanus5:28 21 Feb '11  
Generalsmall problem Pinmemberwcccodeproject20:52 30 Dec '10  
GeneralUnicode Pinmemberdima polyakov13:31 22 May '07  
GeneralGood class, but bad code quality Pinmembermath|fourier4:41 11 Oct '06  
GeneralRe: Good class, but bad code quality PinmemberRenjith Ramachandran18:43 23 Nov '06  
GeneralGood Control Pinmemberbaiju.km2:38 2 Nov '05  
Generalwithout using MFC Pinmembermaharsoft2:17 6 Jan '04  
QuestionIncorrect colors? PinmemberdennisV14:03 3 Dec '03  
AnswerRe: Incorrect colors? Pinmemberfoxbat2:19 3 Jan '04  
GeneralHyperlink Color in Win XP PinmemberSVarnavsky11:40 18 Oct '03  
GeneralRe: Hyperlink Color in Win XP Pinmemberrenjith_sree7:11 6 Feb '06  
GeneralBug Pinmemberironfelix20:56 2 Sep '03  
GeneralBackground color and transparency PinmemberAppstmd0:02 18 Jul '03  
Questionwhy this class can not use create? Pinsusspoor22:01 31 May '03  
AnswerRe: why this class can not use create? PinmemberRenjith R22:35 31 May '03  
GeneralRe: why this class can not use create? Pinmembersaptor11:17 20 Jan '05  
GeneralRe: why this class can not use create? Pinmemberzwzzj20:58 16 Mar '07  
GeneralBig Big Bugs!!! Pinmemberpsusong17:02 31 May '03  
GeneralRe: Big Big Bugs!!! Pinmembertijske2:22 22 Mar '06  
Generalexcellent Pinmemberasrx1:11 28 Jan '03  
GeneralRe: excellent PinmemberRenjith R4:06 28 Jan '03  
GeneralStandard hand cursor PinmemberTak3:57 29 Dec '02  
GeneralRe: Standard hand cursor PinmemberRenjith R6:30 29 Dec '02  
GeneralRe: Standard hand cursor PinmemberTak6:37 29 Dec '02  
GeneralRe: Standard hand cursor PinmemberRenjith R13:59 29 Dec '02  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 27 Dec 2002
Article Copyright 2002 by Renjith Ramachandran
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid