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 :-
- Link to the URL and EMails ,and can
be link in to another child dialog
- Customize the colors of link, visited and hover (if you do not specify, they use the standard style)
- 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 :-
- Add MyHyperlink.cpp and MyHyperlink.h to the project.
- Include MyHyperlink.h in the header file where the controls are defined
- 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 :-
m_Static1.SetLinkUrl("www.codeproject.com");
m_Static1.ActiveToolTip(1);
m_Static1.SetTootTipText("Click Here to go Codeproject");
m_Static1.SetToolTipBgColor(RGB(0, 0, 0));
m_Static1.SetToolTipTextColor(RGB(0, 255, 0));
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..");
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