Using the Hyperlink Classes
ATL applications can directly use the hyperlink classes. Non-ATL-enabled MFC applications, however, must include the ATL base headers. The following steps show you how to add the requisite ATL support to an MFC application.
1. Include the following lines in your stdafx.h header file.
 
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <atlwin.h>
2. Within your application file (for example, MyApp.cpp) define an instance of CComModule at global scope.
 
CComModule _Module;
3. Within the application’s InitInstance() function, initialize the ATL COM module using the CComModule::Init() method.
 
_Module.Init(NULL, AfxGetInstanceHandle());
4. When using the SECRichHyperlink class, MFC applications should initialize the rich edit control at run time. This can be done by calling the AfxInitRichEdit() MFC API from within your InitInstance() function.
Now that the requisite ATL support has been added, the following implementation steps are identical for both ATL and MFC applications.
5. Add an SECHyperlink or SECRichHyperlink data member to the parent class that is expected to house the hyperlink.
 
// Add an instance of the SECHyperlink class
SECHyperlink m_Hyperlink;
6. When using the hyperlink control in a dialog, it is possible to substitute an existing place-holder with the hyperlink using the SECHyperlink::AttachHyperlink() method. As an alternative, or in a non-dialog scenario, you can also use the SECHyperlink::Create() function to create the control. This can be done from within the WM_INITDIALOG handler or the WM_CREATE handler in the case of a conventional CWnd/CWindow.
 
// IDC_STATIC_RICHLINK is the placeholder control
m_richHyperlink.AttachHyperlink(m_hWnd, IDC_STATIC_RICHLINK);
7. Initialize the control with the hyperlink text as well as the user-friendly display text. The SECHyperlink::SetHyperlink() and SECHyperlink::SetDisplayText() methods can be used for this purpose.
 
m_hyperlink.SetDisplayText("My Hyperlink text");
m_hyperlink.SetHyperlink("http://www.perforce.com");
8. A hot-text delimiter can be specified for the rich-text version of the control by enclosing the hot-text within <> tags.
 
m_richHyperlink.SetDisplayText(
"This is my <status report>");
m_richHyperlink.SetHyperlink("D:\\Reports\\Status1.doc");
9. If you choose, the hyperlink control can automatically resize itself to fit the text when you invoke the SECHyperlink::SizeToText() method with a TRUE parameter.