Click here to Skip to main content
15,896,557 members
Articles / Desktop Programming / WTL

Hyperlink Text View Control

Rate me:
Please Sign up or sign in to vote.
4.50/5 (4 votes)
20 Jun 20021 min read 124.2K   2.2K   37  
Control that shows text and automatically finds and highlights hyperlinks (like http://, www. etc.) so that user can click on them.
// HViewView.h : interface of the CHViewView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_HVIEWVIEW_H__2861FD00_F9FB_4C17_83C6_3DCDE50ABBE9__INCLUDED_)
#define AFX_HVIEWVIEW_H__2861FD00_F9FB_4C17_83C6_3DCDE50ABBE9__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "HyperTextCtrl.h"

class CHViewView : public CDialogImpl<CHViewView>
{
	CHyperTextCtrl m_hc;

public:
	enum { IDD = IDD_HVIEW_FORM };

	BOOL PreTranslateMessage(MSG* pMsg)
	{
		return IsDialogMessage(pMsg);
	}

	BEGIN_MSG_MAP(CHViewView)
		MESSAGE_HANDLER(WM_INITDIALOG, OnCreate)
		MESSAGE_HANDLER(WM_SIZE, OnSize)
		MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
	END_MSG_MAP()

	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		CRect rc(10,10,400,300);
	    m_hc.Create(m_hWnd, rc, NULL, 
			WS_VISIBLE | WS_CHILD | HTC_WORDWRAP | HTC_AUTO_SCROLL_BARS | HTC_UNDERLINE_HOVER | HTC_ENABLE_TOOLTIPS, 
			0, IDC_HYPERLINK_CTRL);

		m_hc.SetWindowText(
			"http://www.nd.edu/~crosenbe/jobs.html Alternative Careers for Art Historians - guide to career tracks for individuals who have majored in or are contemplating a major in art history.\n\n"
			"http://www.pbs.org/wnet/americanvisions/ American Visions - companion site to the PBS special on the history of American art as told by Time Magazine's art critic, Robert Hughes.\n\n"
			"http://users.hol.gr/~dilos/anistor/cover.htm Anistoriton - magazine of history, archaeology & art history.\n\n"
			"http://www.arthistory.net Art History Network - art history, archaeology and fine art resources on the web.\n\n"
			"http://www.mcad.edu/AICT/html/index.html Art Images for College Teaching - AICT is a royalty-free image exchange resource for the educational community.\n\n"
			"http://www.the-artfile.com/ ArtFile, The - overview of the history of art, including timeline, artists, styles, and galleries.\n\n"
			"http://www.arthistorytv.com/ ArtHistoryTV.com - an internet-only TV channel.\n\n"
			"Thats all.\n\n"
		);

		m_hc.AppendHyperLink("Write comments\n", "Click here to open notepad", "notepad.exe", "");
		m_hc.AppendText("Your suggestions about this component you can send to ");
		m_hc.AppendHyperLink("maq@hotbox.ru\n\n", "Click here to send e-mail", "mailto:maq@hotbox.ru","");
		m_hc.AppendHyperLink("Close this window\n", "Click here to close window", GetParent(), WM_CLOSE, 0, 0);

		CFont fnt;
		fnt.CreatePointFont(90, "Tahoma");
		m_hc.SetFont(fnt.Detach());

		m_hc.SetLinkCursor(LoadCursor(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDC_HAND_POINT)));
		m_hc.SetLinkColor(RGB(0,130,0));
		m_hc.SetHoverColor(RGB(0,30,0));
		return 0;
	}

	LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		CRect rc;
		GetClientRect(rc);
		m_hc.MoveWindow(rc);
		return 0;
	}

	LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		return TRUE;
	}
};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_HVIEWVIEW_H__2861FD00_F9FB_4C17_83C6_3DCDE50ABBE9__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions