
CHLinkCtrl v1.43 An MFC class to support
Hyperlinks
This class allows you to create a static control on a window or dialog which
behaves similar to a hyperlink as seen on a web page. When the mouse moves over
the text the cursor becomes a hand and when you click on the text the hyperlink
is executed.

The enclosed zip file contains the CHLinkCtrl
source code and also includes a VC 2017 solution to build a small demonstration
app.
A place you may find this class useful is to spruce up an otherwise plain "About
box" in your Windows applications.
Copyright
- You are allowed to include the source code in any product (commercial, shareware,
freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to maintain
a single distribution point for the source code.
Updates
v1.43 (21 March 2022)
- Updated copyright details.
- Updated the code to use C++ uniform initialization for all variable
declarations.
v1.42 (27 November 2021)
- Updated copyright details.
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.41 (13 April 2020)
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.40 (1 March 2020)
- Updated copyright details.
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.39 (19 December 2019)
- Fixed various Clang-Tidy static code analysis warnings in the code.
v1.38 (11 September 2019)
- Replaced enum with enum class throughout the code
- Fixed a number of compiler warnings when the code is compiled with VS
2019 Preview
v1.37 (2 June 2019)
- Updated copyright details.
- Updated the code to clean compile on VC 2019
v1.36 (6 August 2018)
- Fixed a number of C++ core guidelines compiler warnings. These changes
mean that the code will now only compile on VC 2017 or later.
- Replaced enum with enum class throughout the codebase
v1.35 (17 February 2018)
- Updated copyright details.
- Reworked the class to use STN_CLICKED notifications for handling the
hyperlink click instead of via OnLButtonUp. Please note that the control now
requires the SS_NOTIFY style to be set. Thanks to "sen" for reporting this
issue.
- Added SAL annotations to all the code
v1.34 (15 October 2017)
- Updated copyright details.
- Replaced NULL with nullptr throughout the codebase. This means that the
code now requires VC 2010 at a minimum to compile.
- Removed some unnecessary defines from HLinkCtrl.cpp.
- Replaced LONG with LSTATUS for all registry functions.
- Replaced raw registry API calls throughout the code with ATL::CRegKey
class.
- Replaced "BOOL" values throughout the code with "bool".
- Replaced CString::operator LPC*STR() calls with CString::GetString
calls.
v1.33 (22 November 2015)
- Verified the code compiles cleanly on VC 2015.
- Updated the sample apps main icon.
v1.32 (18 January 2015)
- Updated copyright details.
- Updated the code and sample app to clean compile on VC 2013
v1.31 (28 June 2013)
- Updated the sample app to draw a hatched background in debug mode to verify
that the hyperlink class works correctly where the parent window has a custom
drawn background.
v1.30 (23 June 2013)
- Updated copyright details.
- Updated the sample app to clean compile on VC 2010 and later.
- Made a number of Getter methods of the CHLinkCtrl class const.
- Updated the zip file to include the correct project files. Thanks to "Franc"
for reporting this issue.
v1.29 (22 December 2008)
- The code now uses TrackMouseEvent to implement support for highlighting
instead of capturing the mouse.
v1.28 (22 December 2008)
- Updated copyright details
- Removed VC 6 style AppWizard comments from the code
- The code has now been updated to support VC 2005 or later only
- Code now compiles cleanly using Code Analysis (/analyze)
- Made the "Open" method virtual
- The verb passed to ShellExecute can now be customized.
- Notifications for the static control are now enabled via a WM_NCHITTEST
message handler
- All the default colors and behaviour for the hyperlink are now taken from
the users default settings at HKEY_CURRENT_USER\Software\Microsoft\Internet
Explorer\Settings. These settings include a new setting which controls the underline
behaviour. The programmer can still change these values if you so desire.
- Fixed a redraw glitch when the control is sent what looks like unsolicited
reflected CTLCOLOR messages from the parent even when it does not look like
the control needs repainting. The control now does not draw transparently, instead
it uses SetDCBrushColor and GetStockObject(DC_BRUSH). Please note that this
means that the control will only work on Windows 2000 or later and requires
_WIN32_WINNT to be defined >= 0x0500
v1.27 (2 February 2007)
- Fixed a small redraw glitch when you use "Use the System Font"
setting in the dialog resource editor in VC 2005.
- Fixed a small redraw glitch when the enabled state of the control is changed.
v1.26 (27 January 2007)
- Updated copyright details.
- Class now by default sports a tooltip with the hyperlink text as its data.
- Class now only shows the underline when the hyperlink is highlighted.
- The "EnableLink" property has now been removed. Instead you can
use the standard windows WS_DISABLED style. By also doing this, the code now
no longer requires the disabled cursor resource.
- Class now reverts to standard static control colors and style when disabled.
- Removed code which loads up the IDC_HLINKCTRL_ENABLED_CURSOR cursor. This
now means that the code has no dependency on any resources which you need to
add to your project.
v1.25 (21 December 2006)
- Updated copyright details
- Optimized CHLinkCtrl constructor code
- Optimized CHLinkPage constructor code
- Code now compiles cleanly on VC 2005
- Code now only uses ShellExecute approach to executing hyperlinks
- Stripped context menu support from the class. This provides for a more leaner
control implementation. Derived classes are of course free to implement their
own functionality
- Reviewed all TRACE statements for correctness
- Renamed module to be HLinkCtrl to be consistent with the name of the class
- Hyperlink is now executed on mouse up instead of on mouse down. This is
to maintain consistency with how a command button operates
v1.24 (18 February 2002)
- Fixed a problem where the underlined style was not being set for the control
when the "NO wrap" window style was applied.
- Now includes copyright message in the source code and documentation.
v1.23 (12 January 2000)
- The zip file lists disabled.cur in the home directory, not in the RES directory
where it belongs.
- When compiling for UNICODE, the copy-to-clipboard feature sets the incorrect
clipboard type CF_TEXT, not CF_UNICODETEXT. This results in only the first character
being available in the clipboard.
v1.22 (11 December 1999)
- Now supports a disabled hyperlink cursor similar to the offline cursor in
IE via the new Set / GetEnabledLink functions.
v1.21 (29 March 1999)
- Now uses IDC_HAND cursor (available on 98 and Windows 2000) in preference
to the built in cursor which CHLinkCtrl provides.
- Code is now Unicode compliant and build configurations are provided.
- Documentation is now provided in HTML format similar to all of the classes
of the author.
- All the methods of the class are now fully documented in the help file
- Copy Shortcut context menu item now actually works !.
- Removed a number of unused variables in the code.
v1.2 (6 November 1997)
- Improved drawing of control by handling WM_CTLCOLOR through MFC message
reflection
- class now derived from CStatic as it should have been from the beginning
- Dropped support for shrink to fit as now no need
- Description is now taken from controls window text
- Now using more standard visited and unvisited colors
- streamlined some of the functions declarations
- Wait cursor is now shown when a shortcut is being saved and when connected
to.
- Context menu for control can now be turned off if so desired
v1.1 (17 September 1997)
- Hot tracking look
- Drop shadow effect
- Context Menu
- Properties dialog ala IE3
- Add to Favorites & Desktop
- Clipboard support
v1.02 (8 September 1997)
- Number of minor tweaks to the source code.
v1.01 (9 January 1997)
- Small bug fix relating to duplicate functions.