Click here to Skip to main content
15,886,799 members
Articles / Desktop Programming / MFC

Small C++ class to transform any static control into a hyperlink control

Rate me:
Please Sign up or sign in to vote.
4.31/5 (23 votes)
6 Feb 200611 min read 100K   1.3K   41  
This class is small, efficient and is compatible with Win32 API programs and MFC programs as well.
/*
 * Module ID: mfcpp.h
 * Title    : MFC++: Extend MFC classes.
 *
 * Author   : Olivier Langlois <olanglois@sympatico.ca>
 * Date     : December 12, 2005
 */

#ifndef   _MFCPP_H_
#define   _MFCPP_H_

#include <afxext.h>         // MFC extensions
#include <afxcmn.h>			// MFC support for Windows Common Controls

/*
 * Defines
 */
#define URLMAXLENGTH 256

/*
 * Forward declaration
 */
class CHyperLink;

class CStrechyStatusBar : public CStatusBar
{
protected:
	void MakeStrechy(void)
	{
		UINT nID, nStyle;
		int  cxWidth;
		/*
		 * Set the first strechy indicator width to its minimum to
		 * make sure that the right side indicators do not disapear when
		 * the status bar width is reduced.
		 */
		GetPaneInfo(0, nID, nStyle, cxWidth);
		SetPaneInfo(0, nID, nStyle, 1);
	}
};

class CSubclassToolTipCtrl : public CToolTipCtrl
{
// Operations
public:
/******************************************************************************
 *
 * Name      : AddWindowTool
 *
 * Purpose   : Add a window tool by using the Tooltip subclass feature
 *
 * Parameters:
 *     hWin    (HWND)    Tool window
 *     pszText (LPTSTR)  Tip text (can also be a string resource ID).
 *
 * Return value : Returns TRUE if successful, or FALSE otherwise.
 *
 ****************************************************************************/
	BOOL AddWindowTool( HWND hWin, LPTSTR pszText );

/******************************************************************************
 *
 * Name      : AddRectTool
 *
 * Purpose   : Add a rect tool by using the Tooltip subclass feature
 *
 * Parameters:
 *     hWin    (HWND)    Tool window parent
 *     pszText (LPTSTR)  Tip text (can also be a string resource ID).
 *     lpRect  (LPCRECT) Tool rect
 *     nIDTool (UINT)    User defined Tool ID
 *
 * Return value : Returns TRUE if successful, or FALSE otherwise.
 *
 ****************************************************************************/
	BOOL AddRectTool( HWND hWin, LPTSTR pszText, LPCRECT lpRect, UINT nIDTool );

// Implementation
	void FillInToolInfo(TOOLINFO& ti, HWND hWnd, UINT nIDTool) const;
};

class CHyperLinkDlg : public CDialog
{
public:
	CHyperLinkDlg(UINT nIDTemplate) : CDialog(nIDTemplate) {}
protected:
/******************************************************************************
 *
 * Name      : setURL
 *
 * Purpose   : Convert the static control id and load URL string from
 *             resource associated with id.
 *
 * Parameters:
 *     ctr     (CHyperLink &) Reference to the hyperlink object to setup.
 *     id      (int)          Static control ID and URL String ID.
 *
 * Return value : None.
 *
 ****************************************************************************/
	void setURL(CHyperLink &ctr, int id);
};

#endif /* _MFCPP_H_ */

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
Canada Canada
I'm located in Montreal,Canada and I graduated in electrical engineering at E.T.S.

Highly experienced C++ developer. I have been working 3 years at Nortel Networks on their Next-gen OC-768 products firmware. I then worked for the FAA 3 years on their next-gen Oceanic Air Traffic Control system. Followed by a short period in the video game industry at Quazal, the online multiplayer middleware provider and now I am in the Internet audio/video streaming business at StreamTheWorld.

To contact me, visit my website

Comments and Discussions