Introduction
This control works like a static control, but have some enhancements.
The main is that it recognizes and shows hyperlinks in text.
Feautures
- Automatically recognizes hyperlinks
- Word wrapped text view
- Highlights hyperlink when hover
- Auto show scrollbars
- Manually added hyperlinks that can do some operations
- Tool tips for hyperlinks
Requirements
Next files required to be included before "HyperTextCtr.h":
atlstr.h
atltypes.h
atlctrls.h
atlscrl.h
Also this control uses two STL classes: std::vector
and std::list
How to use it in your own applications
- Create WTL project and add following header files to your
stdafx.h
file:
#include <atlstr.h>
#include <atltypes.h>
#include <atlctrls.h>
#include <atlscrl.h>
#include "HyperTextCtrl.h"
- To support mouse wheel define the following in stdafx.h before all includes:
#define _WIN32_WINNT 0x0400
- Add HyperTextControl.h to solution
- Add variable declaration inside view class:
CHyperTextCtrl m_hc;
- Create control and set control's properties in WM_CREATE message handler:
m_hc.Create(m_hWnd, rcDefault, NULL,
WS_VISIBLE | WS_CHILD | HTC_WORDWRAP |HTC_AUTO_SCROLL_BARS |
HTC_UNDERLINE_HOVER | HTC_ENABLE_TOOLTIPS, 0, 0);
CFont fnt;
fnt.CreatePointFont(90, "Tahoma");
m_hc.SetFont(fnt.Detach());
m_hc.SetLinkColor(RGB(0,130,0));
m_hc.SetHoverColor(RGB(0,30,0));
Supported additional control styles:
HTC_WORDWRAP
Word wrap text
HTC_AUTO_SCROLL_BARS
Auto show/hide scroll bars
HTC_UNDERLINE_LINKS
Underline links
HTC_UNDERLINE_HOVER
Underline hover links
HTC_ENABLE_TOOLTIPS
Enable hyperlink tool tips
- Add text and/or manually add hyperlinks:
m_hc.SetWindowText("The http://www.codeproject.com is a very nice place for the sources.");
m_hc.AppendHyperLink("Launch notepad\n", "Click here to open notepad", "notepad.exe", "");
m_hc.AppendText("Send mail to ");
m_hc.AppendHyperLink("author\n\n", "Click here to send e-mail", "mailto:maq@...","");
m_hc.AppendHyperLink("Close this window\n", "Click here to close window",
m_hWnd, WM_CLOSE, 0, 0);
- Add the following code to WM_SIZE message handler of view to fit control into
the view when resizing: CRect rc;
GetClientRect(rc);
m_hc.MoveWindow(rc);
Environment
This control was created with VC7, WTL7.
It has been tested on Windows XP Pro English.
History
11.06.2002
+ CHyperTextCtrlFSB - uses flat scroll bars
+ SetTextColor, SetBkColor
- bugs fixed
08.06.2002
+ Now CHyperTextCtrl inherits from CHyperTextCtrlT<>
07.06.2002
+ .cpp file removed. Now all code is in HyperTextCtrl.h
- bugs fixed
* Tested on WinXP, VC++7, WTL7
01.06.2001
+ Control was created.
* Tested on Win2K, VC++6 SP3, WTL3.1