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

XHTMLTipOfTheDay - HTML Tip of the Day Dialog

Rate me:
Please Sign up or sign in to vote.
4.19/5 (17 votes)
14 Jun 2004CPOL4 min read 72.2K   1.3K   45  
XHTMLTipOfTheDay is a Tip of the Day dialog that displays HTML and has forward and back buttons.
// XHTMLStatic.h  Version 1.2
//
// This software is released into the public domain.  You are free to use it
// in any way you like, except that you may not sell this source code.
//
// This software is provided "as is" with no expressed or implied warranty.
// I accept no liability for any damage or loss of business that this software
// may cause.
///////////////////////////////////////////////////////////////////////////////

#ifndef XHTMLSTATIC_H
#define XHTMLSTATIC_H

#include "XNamedColors.h"

/////////////////////////////////////////////////////////////////////////////
// CXHTMLStatic window

struct XHTMLSTATIC_APP_COMMAND
{
	HWND	hWnd;			// HWND of window to receive message
	UINT	uMessage;		// message sent to parent
	WPARAM	wParam;			// user defined data returned in wParam parameter
	TCHAR *	pszCommand;		// string that ties this entry to HTML hyperlink
};

struct XHTMLSTATIC_CHAR_ENTITIES
{
	TCHAR *	pszName;		// string entered in HTML - e.g., " "
	TCHAR	cCode;			// code generated by XHTMLStatic
	TCHAR	cSymbol;		// character symbol displayed
};

class CXHTMLStatic : public CStatic
{
// Construction
public:
	CXHTMLStatic();
	virtual ~CXHTMLStatic();
	void Init();

// Attributes
public:
	virtual COLORREF SetBkColor(COLORREF rgb) 
	{
		COLORREF oldrgb = m_crBackGround;
		m_crBackGround = rgb;
		return oldrgb;
	}
	virtual COLORREF SetBkColor(LPCTSTR lpszColor) 
	{
		ASSERT(lpszColor);
		CXNamedColors nc(lpszColor);
		COLORREF oldrgb = m_crBackGround;
		m_crBackGround = nc.GetRGB();
		return oldrgb;
	}
	COLORREF GetBkColor() const { return m_crBackGround; }

	virtual COLORREF SetTextColor(COLORREF rgb) 
	{
		COLORREF oldrgb = m_crText;
		m_crText = rgb;
		return oldrgb;
	}
	virtual COLORREF SetTextColor(LPCTSTR lpszColor) 
	{
		ASSERT(lpszColor);
		CXNamedColors nc(lpszColor);
		COLORREF oldrgb = m_crText;
		m_crText = nc.GetRGB();
		return oldrgb;
	}
	COLORREF GetTextColor() const { return m_crText; }
	void SetMargins(int nLeftMargin, int nRightMargin)
	{
		m_nLeftMargin = nLeftMargin;
		m_nRightMargin = nRightMargin;
	}
	void SetAppCommands(XHTMLSTATIC_APP_COMMAND * paAppCommands, int nAppCommands)
	{
		if (m_paAppCommands)
			delete [] m_paAppCommands;
		m_paAppCommands = NULL;

		m_nAppCommands = 0;

		if (paAppCommands && (nAppCommands > 0))
		{
			m_paAppCommands = new XHTMLSTATIC_APP_COMMAND[nAppCommands];
			ASSERT(m_paAppCommands);
			memcpy(m_paAppCommands, paAppCommands, 
				sizeof(XHTMLSTATIC_APP_COMMAND) * nAppCommands);
			m_nAppCommands = nAppCommands;
		}
	}
	void SetLogFont(const LOGFONT * pLogFont)
	{
		ASSERT(pLogFont);
		memcpy(&m_lf, pLogFont, sizeof(m_lf));
		m_bLogFont = TRUE;
	}
	void SetWindowText(LPCTSTR lpszString);


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CXHTMLStatic)
protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

// Implementation
protected:
	int		FormatText(HDC hdc, LPCTSTR lpszText, RECT * pRect, int nInitialXOffset);
	TCHAR	GetCharEntity(TCHAR cCode);
	CString	GetNextWord(TCHAR **ppText, BOOL *pbReturnSeen);
	LONG	GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata);
	BOOL	GotoURL(LPCTSTR url, int showcmd);
	void	InitCharEntities();
	BOOL	IsBlank(LPCTSTR lpszText);
	BOOL	ProcessAppCommand(LPCTSTR lpszCommand);

	COLORREF		m_crBackGround;
	COLORREF		m_crText;
	LOGFONT			m_lf;
	BOOL			m_bLogFont;
	BOOL			m_bUnderline;
	BOOL			m_bBold;
	BOOL			m_bItalic;
	BOOL			m_bStrikeThrough;
	BOOL			m_bSubscript;
	BOOL			m_bSuperscript;
	BOOL			m_bHorizontalRule;
	int				m_nHorizontalRuleSize;
	CFont			m_font;
	BOOL			m_bInAnchor;
	CPtrArray		m_AnchorRectPtrs;
	CStringArray	m_AnchorUrls;
	BOOL			m_bHyperlinkTimer;
	BOOL			m_bOnHyperlink;
	HCURSOR			m_hLinkCursor;
	HCURSOR			m_hPrevCursor;
	int				m_nLeftMargin, m_nRightMargin;
	int				m_yStart;
	BOOL			m_bGeneratedText;
	int				m_nAppCommands;
	static XHTMLSTATIC_CHAR_ENTITIES	m_aCharEntities[];
	XHTMLSTATIC_APP_COMMAND *			m_paAppCommands;

	// Generated message map functions
protected:
	//{{AFX_MSG(CXHTMLStatic)
	afx_msg void OnPaint();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	afx_msg void OnDestroy();
	//}}AFX_MSG
	afx_msg void OnClicked();

	DECLARE_MESSAGE_MAP()
};

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

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

#endif //XHTMLSTATIC_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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions